Opened 4 years ago

Closed 4 years ago

#25185 closed New feature (fixed)

Support for serialization of `functools.partial` objects in migrations

Reported by: Piper Merriam Owned by: Piper Merriam
Component: Migrations Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It would be nice for the django migration engine to support serialization of functools.partial objects. I don't see any obvious barriers to this beyond adding additional logic to the MigrationWriter.serialize method to handle objects of that type.

A general description of the approach that seems appropriate is as follows.

For an object x which passes the check isinstance(x, functools.partial)

  • perform MigrationWriter.serialize(x.func) to get the serialized function string and imports.
  • perform MigrationWriter.serialize(x.args) to get the serialized positional arguments that have been curried.
  • perform MigrationWriter.serizlize(x.keywords) to get the serialized keyword arguments that have been curried.
  • construct the string to reproduce the partial object with something like "functools.partial({0}, *{1}, **{2})".format(func_str, pos_args_str, keyword_args_str)

Is this functionality desired and worth supporting?

Change History (6)

comment:1 Changed 4 years ago by Piper Merriam

Pull request which adds this feature.

https://github.com/django/django/pull/5061

Last edited 4 years ago by Piper Merriam (previous) (diff)

comment:2 Changed 4 years ago by Piper Merriam

Has patch: set
Owner: changed from nobody to Piper Merriam
Status: newassigned

comment:3 Changed 4 years ago by Carl Meyer

Triage Stage: UnreviewedAccepted

It's a useful feature and the implementation is straightforward. I'm in favor of including it.

I have a question about the code, but I'll wait and comment on the pull request once you open it. Thanks for the contribution!

comment:4 in reply to:  3 Changed 4 years ago by Piper Merriam

Replying to carljm:

It's a useful feature and the implementation is straightforward. I'm in favor of including it.

I have a question about the code, but I'll wait and comment on the pull request once you open it. Thanks for the contribution!

Pull request for comment https://github.com/django/django/pull/5061

comment:5 Changed 4 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

Looks good, pending some cosmetic comments.

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 537818a:

Fixed #25185 -- Added support for functools.partial serialization in migrations

Note: See TracTickets for help on using tickets.
Back to Top