Code

Opened 7 years ago

Closed 7 years ago

#4633 closed (wontfix)

Unable to serialize a not yet saved model which has many-to-many relation.

Reported by: Bear Owned by: nobody
Component: Core (Serialization) Version: master
Severity: Keywords: model, serialize, many-to-many
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If I try to serialize a not yet saved model which has many-to-many relation, it will raise ValueError while serialize many-to-many field.

for instance:

from django.contrib.auth.models import User

u = User(username="bear", password="bear", email="blp330@…")

from django.core import serializers

serializers.serialize("json", [u])

=>

ValueError: <class 'django.contrib.auth.models.Group'> instance needs to have a
primary key value before a many-to-many relationship can be used.

This makes inconvenient while use ajax in some situation.

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

Serialization is only intended for use of objects that are saved and in the database. Unless you can provide an example of where AJAX would require the serialization of an incomplete object, I'm marking this wontfix.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.