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

REST API: Community Logo Update after deletion results in 500 IntegrityError #2698

Closed
Samk13 opened this issue Jun 10, 2024 · 6 comments · Fixed by inveniosoftware/invenio-communities#1177
Labels
bug Something isn't working

Comments

@Samk13
Copy link
Member

Samk13 commented Jun 10, 2024

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.

IntegrityError
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.

Steps to Reproduce

Using API:

  1. Create a new community POST {{baseURL}}/api/communities
  2. Retrieve the logo (will initially return "No logo exists for this community") GET {{baseURL}}/api/communities/{{community-id}}/logo
  3. Upload a logo for the community: PUT {{baseURL}}/api/communities/{{community-id}}/logo
  4. Delete the logo: DELETE {{baseURL}}/api/communities/{{community-id}}/logo
  5. Attempt to upload a new logo for the community: PUT {{baseURL}}/api/communities/{{community-id}}/logo
  6. See error

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.

  • get the community by id and from the response links, try to get logo
    https://127.0.0.1:5000/api/communities/611b4ac8-0ec5-4e9a-8c76-384af4f8426d/logo
    you get
{
    "status": 403,
    "message": "Permission denied."
}
  • inspecting DB, communities_files table when deleting the logo, JSON column becomes Null for the community selected. adding an empty dict will show the previous logo image again.

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.

    [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)
    // Werkzeug Debugger

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)

@Samk13 Samk13 added the bug Something isn't working label Jun 10, 2024
@Samk13 Samk13 changed the title REST API: Community Logo Upload Error after deletion - 500 Internal Server REST API: Community Logo Upload Error after deletion - 500 Internal Server IntegrityError Jun 10, 2024
@Samk13
Copy link
Member Author

Samk13 commented Jun 10, 2024

You can also try with the UI:
upload a community picture, delete it, and try to upload it again.

@Samk13 Samk13 changed the title REST API: Community Logo Upload Error after deletion - 500 Internal Server IntegrityError REST API: Community Logo Update Error after deletion - 500 Internal Server IntegrityError Jun 11, 2024
@Samk13 Samk13 changed the title REST API: Community Logo Update Error after deletion - 500 Internal Server IntegrityError REST API: Community Logo Update 500 IntegrityError Error after deletion Jun 11, 2024
@Samk13 Samk13 changed the title REST API: Community Logo Update 500 IntegrityError Error after deletion REST API: Community Logo Update after deletion results in 500 IntegrityError Jun 11, 2024
@Samk13
Copy link
Member Author

Samk13 commented Jun 13, 2024

The community logos get reported as corrupted in the logs, see:

2024-06-13 13:04:26,384: INFO/ForkPoolWorker-5] Task invenio_stats.tasks.aggregate_events[03ba696c-afe8-4d4f-9fae-341a02b0e93d] succeeded in 0.16076873199926922s: [[(0, 0), (0, 0), (0, 0), (0, 0)], None]
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Files integrity report [2024-06-13 11:04:26]
From: info@inveniosoftware.org
To: info@inveniosoftware.org
Date: Thu, 13 Jun 2024 13:04:26 +0200
Message-ID: <171827666637.35607.16811102420004276780@nvidia-2070.lan>



The following files were flagged as 'unhealthy'. This means that the checksum check failed or timed out. Please take any action if needed.

ID: bf4dfb26-41fc-42dd-bfef-28d3ce448009
URI: /home/samk13/.pyenv/versions/3.9.19/envs/kth-rdm-prod-rc2/var/instance/data/bf/4d/fb26-41fc-42dd-bfef-28d3ce448009/data
Name: logo
Created: 2024-06-10 14:44:55.207925
Checksum: md5:d41d8cd98f00b204e9800998ecf8427e
Last check date: 2024-06-13 11:04:26.311230
Last check FAILED with result: None
--------------------------------------------------------------------------------
ID: 95366f3d-fd42-4615-92a1-fc441e2c1d5d
URI: /home/samk13/.pyenv/versions/3.9.19/envs/kth-rdm-prod-rc2/var/instance/data/95/36/6f3d-fd42-4615-92a1-fc441e2c1d5d/data
Name: Screenshot from 2024-06-03 15-33-29.png
Created: 2024-06-05 12:59:19.639676
Checksum: md5:4ce114620c7dfdbcc537c4ed654b9229
Last check date: 2024-06-13 11:04:26.310047
Last check FAILED with result: None
Record: https://127.0.0.1/records/edcbj-mwq39
--------------------------------------------------------------------------------
ID: a6afc875-4f60-4599-bb3c-cb53b307bb0b
URI: /home/samk13/.pyenv/versions/3.9.19/envs/kth-rdm-prod-rc2/var/instance/data/a6/af/c875-4f60-4599-bb3c-cb53b307bb0b/data
Name: logo
Created: 2024-06-05 12:59:06.697470
Checksum: md5:4ce114620c7dfdbcc537c4ed654b9229
Last check date: 2024-06-13 11:04:26.322995
Last check FAILED with result: None
--------------------------------------------------------------------------------

-------------------------------------------------------------------------------
[2024-06-13 13:04:26,387: INFO/ForkPoolWorker-8] Task invenio_app_rdm.tasks.file_integrity_report[803af6ed-f2f6-4461-b903-85d8ddb2d10e] succeeded in 0.16613979399971868s: None
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.

@max-moser
Copy link
Contributor

max-moser commented Jun 28, 2024

In our test instance, uploading community logos, deleting, rinsing and repeating, works as expected.

We're currently also running on invenio-app-rdm version 12.0.0rc2

@Samk13
Copy link
Member Author

Samk13 commented Jun 28, 2024

hmm,
I tried in both K8s, and local setup, and in both, they are failing!
@max-moser Could you try setting up a fresh instance of V12rc2 or latest, and try again?

delete-logo

@Samk13
Copy link
Member Author

Samk13 commented Jun 28, 2024

image
I was able to reproduce it on CERN testing site as well:
https://inveniordm.web.cern.ch/communities/community-test/settings

@max-moser
Copy link
Contributor

Update: With a fresh installation of our own instance, I was able to reproduce it as well – although it did take a few tries.
Stack trace:

127.0.0.1 - - [28/Jun/2024 14:43:10] "PUT /api/communities/4138ec8e-caa5-4d49-9f13-4718bc45c11c/logo HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
    self.dialect.do_execute(
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/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)=(4138ec8e-caa5-4d49-9f13-4718bc45c11c, logo) already exists.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask/app.py", line 2552, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/werkzeug/middleware/proxy_fix.py", line 187, in __call__
    return self.app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/werkzeug/middleware/dispatcher.py", line 78, in __call__
    return app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask/app.py", line 2552, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/werkzeug/middleware/proxy_fix.py", line 187, in __call__
    return self.app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask/app.py", line 2532, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask_resources/resources.py", line 65, in view
    return view_meth()
           ^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask_resources/content_negotiation.py", line 116, in inner_content_negotiation
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask_resources/parsers/decorators.py", line 51, in inner
    return f(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask_resources/parsers/decorators.py", line 90, in inner
    return f(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/flask_resources/responses.py", line 39, in inner
    res = f(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/invenio_communities/communities/resources/resource.py", line 132, in update_logo
    item = self.service.update_logo(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/invenio_records_resources/services/uow.py", line 376, in inner
    res = f(self, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/invenio_communities/communities/services/service.py", line 261, in update_logo
    record.files["logo"] = stream
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/invenio_records_resources/records/systemfields/files/manager.py", line 75, in inner
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/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/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/invenio_records_resources/records/systemfields/files/manager.py", line 75, in inner
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/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/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/invenio_records/api.py", line 334, in create
    with db.session.begin_nested():
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/engine/util.py", line 235, in __exit__
    with util.safe_reraise():
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/engine/util.py", line 233, in __exit__
    self.commit()
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 832, in commit
    self._prepare_impl()
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 811, in _prepare_impl
    self.session.flush()
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 3449, in flush
    self._flush(objects)
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 3588, in _flush
    with util.safe_reraise():
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 3549, in _flush
    flush_context.execute()
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj
    _emit_insert_statements(
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 1238, in _emit_insert_statements
    result = connection._execute_20(
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1710, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection
    return connection._execute_clauseelement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1577, in _execute_clauseelement
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1953, in _execute_context
    self._handle_dbapi_exception(
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2134, in _handle_dbapi_exception
    util.raise_(
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
    self.dialect.do_execute(
  File "/home/mmoser/.local/share/virtualenvs/inveniordm-tuw-uTBkUtu1/lib/python3.12/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)=(4138ec8e-caa5-4d49-9f13-4718bc45c11c, 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, 28, 12, 43, 10, 381755), 'updated': datetime.datetime(2024, 6, 28, 12, 43, 10, 381760), 'id': UUID('9b5db47f-c160-4dc0-98fb-460c77f174f1'), 'json': '{}', 'version_id': 1, 'key': 'logo', 'record_id': UUID('4138ec8e-caa5-4d49-9f13-4718bc45c11c'), 'object_version_id': None}]
(Background on this error at: https://sqlalche.me/e/14/gkpj)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants