-
Notifications
You must be signed in to change notification settings - Fork 149
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
REST API: Community Logo Update after deletion results in 500 IntegrityError #2698
REST API: Community Logo Update after deletion results in 500 IntegrityError #2698
Comments
You can also try with the UI: |
The community logos get reported as corrupted in the logs, see:
|
In our test instance, uploading community logos, deleting, rinsing and repeating, works as expected. We're currently also running on |
hmm, |
|
Update: With a fresh installation of our own instance, I was able to reproduce it as well – although it did take a few tries.
|
Package version (if known): 12.0.0rc2
Describe the bug
When attempting to upload a logo for a community via the API after deleting an existing logo, a 500 Internal Server Error is returned.
Steps to Reproduce
Using API:
POST {{baseURL}}/api/communities
GET {{baseURL}}/api/communities/{{community-id}}/logo
PUT {{baseURL}}/api/communities/{{community-id}}/logo
DELETE {{baseURL}}/api/communities/{{community-id}}/logo
PUT {{baseURL}}/api/communities/{{community-id}}/logo
Expected behavior
The new logo should be successfully uploaded after the previous logo is deleted, without returning an error.
I tested it on Zenodo and it worked as expected but not the RC2.
Screenshots (if applicable)
Additional context
After deleting an existing logo, attempting to upload a new logo results in a 500 Internal Server Error. This issue does not occur when uploading a logo for the first time.
https://127.0.0.1:5000/api/communities/611b4ac8-0ec5-4e9a-8c76-384af4f8426d/logo
you get
Logs:
response log
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique
constraint "uidx_communities_files_record_id_key"
DETAIL: Key (record_id, key)=(32db299e-b6c0-45d3-96b2-55a9f02c6b88, logo) already exists.
Traceback (most recent call last):
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
self.dialect.do_execute(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "uidx_communities_files_record_id_key"
DETAIL: Key (record_id, key)=(32db299e-b6c0-45d3-96b2-55a9f02c6b88, logo) already exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask/app.py", line 2552, in call
return self.wsgi_app(environ, start_response)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/werkzeug/middleware/proxy_fix.py", line 187, in call
return self.app(environ, start_response)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/werkzeug/middleware/dispatcher.py", line 78, in call
return app(environ, start_response)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask/app.py", line 2552, in call
return self.wsgi_app(environ, start_response)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/werkzeug/middleware/proxy_fix.py", line 187, in call
return self.app(environ, start_response)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask/app.py", line 2532, in wsgi_app
response = self.handle_exception(e)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
response = self.full_dispatch_request()
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask/app.py", line 1825, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask/app.py", line 1823, in full_dispatch_request
rv = self.dispatch_request()
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask/app.py", line 1799, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask_resources/resources.py", line 65, in view
return view_meth()
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask_resources/content_negotiation.py", line 116, in inner_content_negotiation
return f(*args, **kwargs)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask_resources/parsers/decorators.py", line 51, in inner
return f(self, *args, **kwargs)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask_resources/parsers/decorators.py", line 90, in inner
return f(self, *args, **kwargs)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/flask_resources/responses.py", line 39, in inner
res = f(*args, **kwargs)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/invenio_communities/communities/resources/resource.py", line 132, in update_logo
item = self.service.update_logo(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/invenio_records_resources/services/uow.py", line 376, in inner
res = f(self, *args, **kwargs)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/invenio_communities/communities/services/service.py", line 261, in update_logo
record.files["logo"] = stream
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/invenio_records_resources/records/systemfields/files/manager.py", line 75, in inner
return func(self, *args, **kwargs)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/invenio_records_resources/records/systemfields/files/manager.py", line 504, in setitem
self.create(key, obj=obj, stream=stream, data=data)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/invenio_records_resources/records/systemfields/files/manager.py", line 75, in inner
return func(self, *args, **kwargs)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/invenio_records_resources/records/systemfields/files/manager.py", line 163, in create
rf = self.file_cls.create({}, key=key, record_id=self.record.id)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/invenio_records/api.py", line 358, in create
db.session.add(record.model)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/engine/util.py", line 237, in exit
self.rollback()
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in exit
compat.raise_(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
raise exception
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/engine/util.py", line 233, in exit
self.commit()
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 832, in commit
self._prepare_impl()
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 811, in _prepare_impl
self.session.flush()
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3449, in flush
self._flush(objects)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3589, in flush
transaction.rollback(capture_exception=True)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in exit
compat.raise(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise
raise exception
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3549, in _flush
flush_context.execute()
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
rec.execute(self)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
util.preloaded.orm_persistence.save_obj(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj
_emit_insert_statements(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 1238, in _emit_insert_statements
result = connection._execute_20(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1710, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection
return connection._execute_clauseelement(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1577, in _execute_clauseelement
ret = self._execute_context(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1953, in _execute_context
self.handle_dbapi_exception(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2134, in handle_dbapi_exception
util.raise(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise
raise exception
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
self.dialect.do_execute(
File "/home/samk13/.pyenv/versions/3.9.19/envs/test-install/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "uidx_communities_files_record_id_key"
DETAIL: Key (record_id, key)=(32db299e-b6c0-45d3-96b2-55a9f02c6b88, logo) already exists.
[SQL: INSERT INTO communities_files (created, updated, id, json, version_id, key, record_id, object_version_id) VALUES (%(created)s, %(updated)s, %(id)s, %(json)s, %(version_id)s, %(key)s, %(record_id)s, %(object_version_id)s)]
[parameters: {'created': datetime.datetime(2024, 6, 10, 15, 36, 57, 893316), 'updated': datetime.datetime(2024, 6, 10, 15, 36, 57, 893320), 'id': UUID('a345172d-aafe-40a5-a573-11a745d5b5bd'), 'json': '{}', 'version_id': 1, 'key': 'logo', 'record_id': UUID('32db299e-b6c0-45d3-96b2-55a9f02c6b88'), 'object_version_id': None}]
(Background on this error at: https://sqlalche.me/e/14/gkpj)
The text was updated successfully, but these errors were encountered: