Support serializing unsaved models with related fields. #2637
Hey @mdentremont — short answer, No I don't know. :-)
What we've got are two related issues (no PKs on unsaved instances) popping up at the same time with two different fixes.
At first glance the fix here looks fine to me — and it's tested — so, is it the behaviour we want and if so have we caught all the places?
#2641 does the same as your change here, basically adding a
In terms of getting this ready... If you looked at #2641 and thought it through that would help. Is it a related issue that your use-case would bump into coming from the other direction? Is there an obvious test for it? Does your patch fix it already?
Clear enough? Sound reasonable?
- In both ManyRelatedField, provide an empty return when trying to access a relation field if the instance in question has no PK (so likely hasn't been inserted yet) - Add relevant tests - Without these changes, exceptions would be raised when trying to serialize the uncreated models as it is impossible to query relations without a PK - Add test to ensure RelatedField does not regress as currently supports being serialized with and unsaved model
I've reviewed #2638. The issue there was specifically about creating the URL for a the
So that means this is good to go. Thanks for the input!