Opened 7 months ago
Last modified 10 days ago
#36608 assigned Cleanup/optimization
Clarify dumpdata behavior and docs for custom serializers with internal_use_only flag
| Reported by: | ksauder | Owned by: | ksauder |
|---|---|---|---|
| Component: | Core (Management commands) | Version: | 5.2 |
| Severity: | Normal | Keywords: | dumpdata custom serializers |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
As displayed in the diff, the code was simply broken and always raised an exception for custom serializer formats.
After further investigation, this problem could also be solved by adding 'internal_use_only = False' to the classes in the example here βhttps://docs.djangoproject.com/en/5.2/topics/serialization/#custom-serialization-formats. This gets around the "if format in serializers.get_public_serializer_formats()" check, although the old code in the diff still doesn't make sense.
Attachments (1)
Change History (20)
by , 7 months ago
| Attachment: | dumpdata_fix.diff added |
|---|
comment:1 by , 7 months ago
| Description: | modified (diff) |
|---|
comment:2 by , 7 months ago
| Resolution: | β invalid |
|---|---|
| Status: | new β closed |
comment:3 by , 7 months ago
Well, the code is a little broken. It doesn't actually raise a more appropriate message, and the docs do not actually point out that internal_use_only flag must be unset for it to work from the command line. I would suggest a change along the lines of this:
diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py
index 15e615c1d0..9ec9ab76a3 100644
--- a/django/core/management/commands/dumpdata.py
+++ b/django/core/management/commands/dumpdata.py
@@ -177,9 +177,8 @@ class Command(BaseCommand):
try:
serializers.get_serializer(format)
except serializers.SerializerDoesNotExist:
- pass
-
- raise CommandError("Unknown serialization format: %s" % format)
+ raise CommandError("Unknown serialization format: %s" % format)
+ # We found it, but it's not a public serializer. Let the user know
+ raise CommandError("Serialization format %s is flagged for internal_use_only. Set internal_use_only = False in the Serializer to use it here." % format)
def get_objects(count_only=False):
"""
And/or call out the internal_use_only flag near the custom serialization doc and its affect on CLI operation.
comment:4 by , 7 months ago
Doc updates are always welcome π feel free to submit a doc PR for clarification if you like. Also if you feel the error message is lacking you're welcome to submit a PR for that too.
Just FYI you don't necessarily need a ticket for minor docs updates or minor code clarification (for future reference)
comment:6 by , 7 months ago
| Resolution: | invalid |
|---|---|
| Severity: | Release blocker β Normal |
| Status: | closed β new |
| Triage Stage: | Unreviewed β Accepted |
| Type: | Uncategorized β Cleanup/optimization |
Reopening to track the docs clarifications. Also downgrading to not release blocker.
comment:7 by , 7 months ago
| Summary: | dumpdata does not use custom serializers β Clarify dumpdata behavior and docs for custom serializers with internal_use_only flag |
|---|
comment:8 by , 7 months ago
| Owner: | set to |
|---|---|
| Status: | new β assigned |
comment:9 by , 7 months ago
| Has patch: | unset |
|---|
Please mark "Has patch" once a PR is open to our GitHub repository βhttps://github.com/django/django
comment:10 by , 4 months ago
I have opened a PR on this issue; please continue the conversation with me if something is a miss (code/doc reviews are welcome!)
follow-up: 12 comment:11 by , 4 months ago
| Patch needs improvement: | set |
|---|
Thank you. Could you look into fixing the lint failures?
comment:12 by , 4 months ago
Replying to Jacob Walls:
Thank you. Could you look into fixing the lint failures?
sure i'll take a look and fix itππ»
comment:13 by , 4 months ago
| Has patch: | set |
|---|---|
| Patch needs improvement: | unset |
comment:14 by , 4 months ago
| Patch needs improvement: | set |
|---|
follow-up: 17 comment:15 by , 2 months ago
The previous PR was closed unmerged and the author indicated they stopped working on it.
Iβd like to submit a new PR to address the documentation feedback and move this forward.
comment:16 by , 2 months ago
Hi, Iβd like to work on this ticket and submit a documentation-focused PR clarifying the internal_use_only behavior for custom serializers used with dumpdata. Please let me know if thatβs okay.
comment:17 by , 2 months ago
Iβve opened a documentation PR to clarify the internal_use_only behavior for custom serializers: βhttps://github.com/django/django/pull/20591
comment:18 by , 3 weeks ago
Hi, I would like to work on this issue and improve the documentation for dumpdata behavior and custom serializers. Could you please confirm if this issue is still available?
comment:19 by , 10 days ago
Hi, Iβve submitted a PR to improve the documentation:
βhttps://github.com/django/django/pull/20993
Please let me know if any changes are needed. Thanks!
Hi there,
The code isn't broken, the exception should always be raised. The loop is there to provide the chance to raise a more appropriate message rather than "Unknown serialization format".
FYI this information was obtained by simply looking at git blame π