Skip to content

Comments

swev-id: django__django-16950 Prevent clearing non-PK to_field (UUID) defaults during Inline formset add#540

Open
casey-brooks wants to merge 1 commit intodjango__django-16950from
noa/issue-534
Open

swev-id: django__django-16950 Prevent clearing non-PK to_field (UUID) defaults during Inline formset add#540
casey-brooks wants to merge 1 commit intodjango__django-16950from
noa/issue-534

Conversation

@casey-brooks
Copy link

Summary

  • keep BaseInlineFormSet from clearing parent defaults when FK targets a non-PK to_field
  • add ThingWithUUID/SubThingUUIDFK fixtures and inline admin registration for coverage
  • verify admin add flow preserves UUID defaults via regression test

Testing

  • PYTHONPATH=$PWD:$HOME/.nix-profile/lib/python3.11/site-packages DJANGO_SETTINGS_MODULE=tests.test_sqlite python3 tests/runtests.py admin_views --parallel=1

Reproduction

  1. Create ThingWithUUID with SubThingUUIDFK inline pointing to to_field='uuid'.
  2. Open the admin add view and submit a child inline row.
  3. Observe inline validation failing because the parent UUID default is cleared to None.

Closes #534

@casey-brooks casey-brooks requested a review from a team December 24, 2025 18:18
Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks solid. Thanks for adding the regression coverage.

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BaseInlineFormSet change cleanly scopes the default clearing to primary-key backed relations, which prevents the UUID to_field regression without disturbing existing behavior. The new fixture wiring and regression test exercise the admin add flow end-to-end, so we have coverage for the bug. Looks great—thanks for tightening this up.

@rowan-stein rowan-stein changed the base branch from django__django-16950 to main January 11, 2026 19:45
@rowan-stein rowan-stein changed the base branch from main to django__django-16950 January 12, 2026 20:13
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

Successfully merging this pull request may close these issues.

Admin inlines clear non-PK UUIDField default when FK uses to_field (UUID) — parent.id set to None and save fails

3 participants