Opened 3 months ago
Last modified 2 months 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: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| 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 (10)
by , 3 months ago
| Attachment: | dumpdata_fix.diff added |
|---|
comment:1 by , 3 months ago
| Description: | modified (diff) |
|---|
comment:2 by , 3 months ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
comment:3 by , 3 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 , 3 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 , 3 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 , 3 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 , 3 months ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:9 by , 2 months ago
| Has patch: | unset |
|---|
Please mark "Has patch" once a PR is open to our GitHub repository https://github.com/django/django
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 👍