Re: [Django] #34716: Class methods from nested classes cannot be used as Field.default.

27 views
Skip to first unread message

Django

unread,
Jul 17, 2023, 8:52:22 AM7/17/23
to django-...@googlegroups.com
#34716: Class methods from nested classes cannot be used as Field.default.
---------------------------------+------------------------------------
Reporter: Nicolò Intrieri | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by Nicolò Intrieri):

Replying to [comment:2 David Sanders]:
> Also to nitpick the terminology: `Capability` is a nested class, not a
subclass. (fyi for anyone preparing tests/commit message)

You're right, that was inaccurate. Thanks for having fixed the title

--
Ticket URL: <https://code.djangoproject.com/ticket/34716#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 17, 2023, 8:59:51 AM7/17/23
to django-...@googlegroups.com
#34716: Class methods from nested classes cannot be used as Field.default.
---------------------------------+------------------------------------
Reporter: Nicolò Intrieri | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by Nicolò Intrieri):

Replying to [comment:1 Mariusz Felisiak]:
> Thanks for the report. It seems that `FunctionTypeSerializer` should use
`__qualname__` instead of `__name__`:
> {{{#!diff
> diff --git a/django/db/migrations/serializer.py
b/django/db/migrations/serializer.py
> index d88cda6e20..06657ebaab 100644
> --- a/django/db/migrations/serializer.py
> +++ b/django/db/migrations/serializer.py
> @@ -168,7 +168,7 @@ class FunctionTypeSerializer(BaseSerializer):
> ):
> klass = self.value.__self__
> module = klass.__module__
> - return "%s.%s.%s" % (module, klass.__name__,
self.value.__name__), {
> + return "%s.%s.%s" % (module, klass.__qualname__,
self.value.__name__), {
> "import %s" % module
> }
> # Further error checking
>
> }}}
>
> Would you like to prepare a patch? (regression test is required)

I would be very happy to prepare a patch, i will do my best to write a
test that's coherent with the current suite

--
Ticket URL: <https://code.djangoproject.com/ticket/34716#comment:5>

Django

unread,
Jul 17, 2023, 9:01:57 AM7/17/23
to django-...@googlegroups.com
#34716: Class methods from nested classes cannot be used as Field.default.
-------------------------------------+-------------------------------------
Reporter: Nicolò Intrieri | Owner: Nicolò
| Intrieri
Type: Bug | Status: assigned

Component: Migrations | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nicolò Intrieri):

* owner: nobody => Nicolò Intrieri
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34716#comment:6>

Django

unread,
Jul 17, 2023, 12:12:51 PM7/17/23
to django-...@googlegroups.com
#34716: Class methods from nested classes cannot be used as Field.default.
-------------------------------------+-------------------------------------
Reporter: Nicolò Intrieri | Owner: Nicolò
| Intrieri
Type: Bug | Status: assigned
Component: Migrations | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

> I would be very happy to prepare a patch, i will do my best to write a
test that's coherent with the current suite

You can check tests in `tests.migrations.test_writer.WriterTests`, e.g.
`test_serialize_nested_class()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/34716#comment:7>

Django

unread,
Jul 17, 2023, 4:32:16 PM7/17/23
to django-...@googlegroups.com
#34716: Class methods from nested classes cannot be used as Field.default.
-------------------------------------+-------------------------------------
Reporter: Nicolò Intrieri | Owner: Nicolò
| Intrieri
Type: Bug | Status: assigned
Component: Migrations | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nicolò Intrieri):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/17087 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/34716#comment:8>

Django

unread,
Jul 17, 2023, 11:27:51 PM7/17/23
to django-...@googlegroups.com
#34716: Class methods from nested classes cannot be used as Field.default.
-------------------------------------+-------------------------------------
Reporter: Nicolò Intrieri | Owner: Nicolò
| Intrieri
Type: Bug | Status: closed
Component: Migrations | Version: 4.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"e8252fc4451ee2c05779b28e74417174f0a2eeef" e8252fc]:
{{{
#!CommitTicketReference repository=""
revision="e8252fc4451ee2c05779b28e74417174f0a2eeef"
Fixed #34716 -- Fixed serialization of nested class methods in migrations.

Co-authored-by: Nicolò <nicolo....@spinforward.it>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34716#comment:9>

Reply all
Reply to author
Forward
0 new messages