Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings API broken? #6173

Closed
landreev opened this issue Sep 17, 2019 · 1 comment · Fixed by #6176
Closed

Settings API broken? #6173

landreev opened this issue Sep 17, 2019 · 1 comment · Fixed by #6176
Milestone

Comments

@landreev
Copy link
Contributor

It looks like you can no longer modify an existing setting via the API:

curl -X PUT -d FAKE http://localhost:8080/api/admin/settings/:DoiProvider

throws a 500; the error in the server log:

... org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "unique_settings"
  Detail: Key (name, (COALESCE(lang, ''::text)))=(:DoiProvider, ) already exists.
Call: INSERT INTO SETTING (CONTENT, LANG, NAME) VALUES (?, ?, ?)
	bind => [3 parameters bound]
Query: InsertObjectQuery([Setting name::DoiProvider value:FAKE])

I am assuming this is the result of merging the PR #6042 - where we made the settings localize-able.

@landreev
Copy link
Contributor Author

landreev commented Sep 17, 2019

This is the code that has stopped working, in SettingsServiceBean:

public Setting set( String name, String content ) {
        Setting s = new Setting( name, content );
        s = em.merge(s);
        actionLogSvc.log( new ActionLogRecord(ActionLogRecord.ActionType.Setting, "set")
                            .setInfo(name + ": " + content));
        return s;
    }

It's still working for creating a new setting; failing when modifying an existing one. I'm assuming it used to work because the "name" was designated to serve as the @id of the table. Now that the constraint has been removed, EJB tries to create a new entry in the table. But, since there is a database index, unique on the combination of name+value+lang - it ends up throwing the exception above.

If we were to choose to fix this without reverting the original PR, we would simply modify the method above (and any similar methods there) to first look up the setting that the method wants to update, and only create a new one if it does not exist...

@djbrooke djbrooke self-assigned this Sep 17, 2019
@landreev landreev mentioned this issue Sep 17, 2019
5 tasks
@djbrooke djbrooke removed their assignment Sep 17, 2019
@pdurbin pdurbin added this to the 4.17 milestone Oct 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants