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

Deleting OCD instances with related Councilmatic subclasses fails #293

Open
hancush opened this issue Sep 19, 2024 · 0 comments
Open

Deleting OCD instances with related Councilmatic subclasses fails #293

hancush opened this issue Sep 19, 2024 · 0 comments
Assignees

Comments

@hancush
Copy link
Member

hancush commented Sep 19, 2024

This is interesting, since the Councilmatic models specify on_delete=models.CASCADE.

class Organization(opencivicdata.core.models.Organization, CastToDateTimeMixin):
organization = models.OneToOneField(
opencivicdata.core.models.Organization,
on_delete=models.CASCADE,
related_name="councilmatic_organization",
parent_link=True,
)

Could this have to do with our use of parent_link? Related docs: https://docs.djangoproject.com/en/3.2/ref/models/fields/#django.db.models.OneToOneField

This is blocking the correct function of pupa clean on the dashboard.

Example stack trade:

[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - 33 objects in your database have not been seen in 7 days.
Proceeding to deletion because you specified --yes.
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - Deleting Ad Hoc 2028 Olympics Committee...
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - Traceback (most recent call last):
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 242, in _commit
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - 
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - return self.connection.commit()
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - psycopg2.errors.ForeignKeyViolation: update or delete on table "opencivicdata_organization" violates foreign key constraint "councilmatic_core_or_organization_id_2d4baacb_fk_opencivic" on table "councilmatic_core_organization"
DETAIL:  Key (id)=(ocd-organization/30e97a57-c264-4580-8fd6-e77ebee18154) is still referenced from table "councilmatic_core_organization".
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/bin/pupa", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/pupa/cli/__main__.py", line 75, in main
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - subcommands[args.subcommand].handle(args, other)
  File "/usr/local/lib/python3.10/site-packages/pupa/cli/commands/clean.py", line 122, in handle
    self.remove_stale_objects(args.window)
  File "/usr/local/lib/python3.10/site-packages/pupa/cli/commands/clean.py", line 80, in remove_stale_objects
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - obj.delete()
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 967, in delete
    return collector.delete()
  File "/usr/local/lib/python3.10/site-packages/django/db/models/deletion.py", line 400, in delete
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - with transaction.atomic(using=self.using, savepoint=False):
  File "/usr/local/lib/python3.10/site-packages/django/db/transaction.py", line 246, in __exit__
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - connection.commit()
  File "/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py", line 33, in inner
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 266, in commit
    self._commit()
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 241, in _commit
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - with self.wrap_database_errors:
  File "/usr/local/lib/python3.10/site-packages/django/db/utils.py", line 90, in __exit__
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py", line 242, in _commit
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - return self.connection.commit()
django.db.utils.IntegrityError: update or delete on table "opencivicdata_organization" violates foreign key constraint "councilmatic_core_or_organization_id_2d4baacb_fk_opencivic" on table "councilmatic_core_organization"
DETAIL:  Key (id)=(ocd-organization/30e97a57-c264-4580-8fd6-e77ebee18154) is still referenced from table "councilmatic_core_organization".
[2024-09-19, 16:46:03 CDT] {docker.py:391} INFO - Sentry is attempting to send 2 pending events
Waiting up to 2 seconds
Press Ctrl-C to quit
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

No branches or pull requests

1 participant