Repository navigation
Conversation
85d2908 to
39ac9e9
Compare
Merging this PR will not alter performance1 warning
Comparing |
39ac9e9 to
d577f5e
Compare
|
The fix addresses the reported symptoms, but a few things feel under-specified for framework-level code. Flagging the ones I'd want pinned down before merge: 1. Every field with 2. Table names are now assigned before relations, globally The loop runs for every model, not just O2O-pk targets. Default 3. Recursive The 4. This is correct for O2O-pk today, but if 5. The test pins 6. Backend coverage MySQL and MSSQL are left to CI, but this touches FK column generation and table-name assignment timing — both dialect-sensitive. Please confirm those jobs run the new tests, not just the existing suite. 7. Tests depend on model-name ordering
|
2680985 to
be3899d
Compare
be3899d to
aafc452
Compare
|
Thanks for the review! Addressed in aafc452 (also rebased on develop):
|
Description
Fixes three bugs with a model whose primary key is a
OneToOneField. Both the relation and its<field>_idbacking field are flagged pk, and these code paths took the relation, which has no column:A ForeignKeyField to such a model now targets the backing field. Relations are set up in model name order, so when Post comes first, Profile.user is now initialized first, with or without to_field="user_id". That is also what makemigrations now writes: it wrote to_field='user', and the migrated table had no column either. A to_field naming a OneToOneField, as those migrations do, now resolves to its backing field. In that case Profile's table is named early, as Profile.user names its reverse relation after its table; other table names are assigned as before.
The pk filters are registered when the backing field becomes the primary key, and _pk_in_subquery() (#2269) selects _meta.db_pk_column. One-to-one fields referencing each other in a cycle now raise ConfigurationError instead of creating tables without columns.
Motivation and Context
I found no issue for these; related to #1771 / #1783 (many-to-many on such a model). A one-to-one primary key extends a table row for row, and other tables reference the extension: their foreign key silently stored nothing.
How Has This Been Tested?
New tests in tests/test_relations.py (foreign keys from models set up before and after the target, to_field naming the backing field or a one-to-one, pk filters), tests/test_queryset.py (delete and update through a related field), tests/test_table_name.py (M2M through names unchanged with a table_name_generator) and tests/model_setup/ (cycle error, foreign key from a later init_models() call). The full suite passes on SQLite; CI covers PostgreSQL, MySQL and MSSQL.
Checklist:
This fix has been partially implemented by Claude Opus 5.5. All modifications made by the AI have been reviewed by me.