deconstruct returns 3-tuple?

44 views
Skip to first unread message

Christian González

unread,
Sep 18, 2021, 11:06:41 AM9/18/21
to django-developers

Hi,

before I issue a bugreport, I'll ask here first.

On https://docs.djangoproject.com/en/3.2/topics/migrations/#adding-a-deconstruct-method I can read that deconstruct() returns a 3-tuple.

When I see the code in django.db.models.fields.__init__.py, Field.deconstruct() does a

    return (self.name, path, [], keywords)

   

This is a 4-tuple, and even the clone() method written after it calls it with

    name, path, args, kwargs = self.deconstruct()

So, is 3.2 documentation here on a <1.9 status? Am I understanding something not correctly?

Thanks,

Christian

-- 
Dr. Christian González
https://nerdocs.at

Andrew Godwin

unread,
Sep 18, 2021, 6:01:40 PM9/18/21
to '1337 Shadow Hacker' via Django developers (Contributions to Django itself)
As the note in that section explains, that is for custom classes, not for custom fields. Your observation is correct when applied to field deconstruction methods, but not for the system talked about there which lets you do it for arbitrary classes (as part of the values in field desconstructions, usually).

Andrew
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.

Tim Graham

unread,
Sep 18, 2021, 6:03:17 PM9/18/21
to Django developers (Contributions to Django itself)
That documentation is for serializing classes. There's a note box that says, "This return value is different from the deconstruct() method for custom fields which returns a tuple of four items."
Reply all
Reply to author
Forward
0 new messages