Skip to content

Comments

fix: swev-id: django__django-17087 use qualname for nested defaults#539

Open
casey-brooks wants to merge 1 commit intodjango__django-17087from
noa/issue-536
Open

fix: swev-id: django__django-17087 use qualname for nested defaults#539
casey-brooks wants to merge 1 commit intodjango__django-17087from
noa/issue-536

Conversation

@casey-brooks
Copy link

Summary

  • use klass.qualname when serializing bound class methods so nested classes resolve correctly
  • add regression coverage for a nested TextChoices default on WriterTests

Testing

  • PYTHONPATH=$PWD/tests:$PWD DJANGO_SETTINGS_MODULE=tests.test_sqlite .venv/bin/python tests/runtests.py migrations.test_writer.WriterTests.test_serialize_nested_class_method_default --parallel=1
  • .venv/bin/flake8 django/db/migrations/serializer.py tests/migrations/test_writer.py

Reproduction Steps

  1. On django__django-17087, run:
    PYTHONPATH=$PWD/tests:$PWD DJANGO_SETTINGS_MODULE=tests.test_sqlite python tests/runtests.py migrations.test_writer.WriterTests.test_serialize_nested_class_method_default --parallel=1
    
  2. Observed failure:
    AssertionError: "models.CharField(choices=[('A', 'A value'), ('B', 'B value')], default=migrations.test_writer.NestedChoicesWithDefault.default, max_length=1)" != "models.CharField(choices=[('A', 'A value'), ('B', 'B value')], default=migrations.test_writer.WriterTests.NestedChoicesWithDefault.default, max_length=1)"
    

Fixes #536}

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

Test & Lint Summary

  • PYTHONPATH=$PWD/tests:$PWD DJANGO_SETTINGS_MODULE=tests.test_sqlite .venv/bin/python tests/runtests.py migrations.test_writer.WriterTests.test_serialize_nested_class_method_default --parallel=1 (1 test, 1 passed)
  • .venv/bin/flake8 django/db/migrations/serializer.py tests/migrations/test_writer.py (no issues)

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.

Switching to qualname fixes the nested TextChoices default regression. Added test covers the case.

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.

Switching to qualname fixes the missing enclosing class segment for nested TextChoices defaults. Regression test fails without the change and locks in the serialization string. I don't see other regressions.

@casey-brooks
Copy link
Author

casey-brooks commented Jan 11, 2026

Local verification (Python 3.12.12):

  • Tests: PYTHONPATH=$PWD/tests:$PWD DJANGO_SETTINGS_MODULE=tests.test_sqlite python tests/runtests.py migrations.test_writer.WriterTests.test_serialize_nested_class_method_default --parallel=1 → 1/1 passed.
  • Lint: flake8 django/db/migrations/serializer.py tests/migrations/test_writer.py → clean. (Ran via a small wrapper that patches
    importlib.metadata.EntryPoints.get so flake8 3.9.2 works on Python 3.12.)

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.

Looks good. Thanks!

@rowan-stein rowan-stein changed the base branch from django__django-17087 to main January 11, 2026 19:56
@rowan-stein rowan-stein changed the base branch from main to django__django-17087 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.

Fix serialization of nested class methods used as Field.default (swev-id: django__django-17087)

2 participants