Opened 10 years ago
Closed 10 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:2 by , 10 years ago
| Has patch: | set |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
follow-up: 4 comment:3 by , 10 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
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 by , 10 years ago
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 by , 10 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Looks good, pending some cosmetic comments.
Pull request which adds this feature.
https://github.com/django/django/pull/5061