Skip to content

tests: fix flaky sponsor test  #2567

Open
@JacobCoffee

Description

@JacobCoffee

This is a flaky test that fails periodically after latest updates
https://github.com/python/pythondotorg/actions/runs/10887332034/job/30209329967?pr=2527


======================================================================
ERROR: test_save_info_for_image_asset (sponsors.tests.test_forms.SponsorRequiredAssetsFormTest.test_save_info_for_image_asset)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/django/db/backends/utils.py", line 87, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.ForeignKeyViolation: insert or update on table "sponsors_benefitfeatureconfiguration" violates foreign key constraint "sponsors_benefitfeat_polymorphic_ctype_id_0ce3d544_fk_django_co"
DETAIL:  Key (polymorphic_ctype_id)=(100) is not present in table "django_content_type".


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

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/django/test/testcases.py", line 419, in _setup_and_call
    self._post_teardown()
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/django/test/testcases.py", line 1279, in _post_teardown
    self._fixture_teardown()
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/django/test/testcases.py", line 1509, in _fixture_teardown
    connections[db_name].check_constraints()
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/django/db/backends/postgresql/base.py", line 383, in check_constraints
    cursor.execute("SET CONSTRAINTS ALL IMMEDIATE")
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/django/db/backends/utils.py", line 87, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: insert or update on table "sponsors_benefitfeatureconfiguration" violates foreign key constraint "sponsors_benefitfeat_polymorphic_ctype_id_0ce3d544_fk_django_co"
DETAIL:  Key (polymorphic_ctype_id)=(100) is not present in table "django_content_type".

Originally posted by @JacobCoffee in #2527 (comment)

Metadata

Metadata

Assignees

Labels

testsRelates to the test suite

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions