Changes between Initial Version and Version 3 of Ticket #37175


Ignore:
Timestamp:
Jun 24, 2026, 7:06:35 PM (12 days ago)
Author:
Tim Graham
Comment:

First, I removed hardcoded pks where they aren't needed (PR 21364).

Trying to rework the tests that require hardcoded pks may be possible in some cases, however, I believe some form of get_hardcoded_pk() API will be needed, so I feel the most expedient path forward is to merge the patch and leave test refactoring to a later task.

Incidentally, I didn't update serializers and fixtures tests to use get_hardcoded_pk() since it's a bit trickier, but this would also be a useful follow up task. There's a commit on the Django fork used to run the test suite on MongoDB that updates all fixtures to use ObjectIds instead of integers (e.g. "pk": 1, because "pk": "000000000000000000000001",) and this would remain, but the hardcoded pks in files such as tests/fixtures_regress/tests.py could be replaced.

At your request, I created forum topic Adding database backend methods to get hardcoded or nonexistent primary key values for tests to solicit feedback.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37175

    • Property Has patch set
    • Property Cc Simon Charette added
    • Property Triage Stage UnreviewedAccepted
  • Ticket #37175 – Description

    initial v3  
    11While hardcoding primary key values in the Django test suite is avoided as much as possible, sometimes there are legitimate uses. The existing hardcoded integer values, however, don't work on databases that don't use integer primary key values. For example,  MongoDB uses `DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"`.
    22
    3 I propose adding new methods `DatabaseOperations.get_hardcoded_pk()` and `get_nonexistentd_pk()` to allow a database backend to provide suitable values, minimizing the size of the Django fork needed for running the test suite on such databases.
     3I propose adding new methods `DatabaseOperations.get_hardcoded_pk()` and `get_nonexistent_pk()` to allow a database backend to provide suitable values, minimizing the size of the Django fork needed for running the test suite on such databases.
Back to Top