-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get_url(): AttributeError: 'OrderedDict' object has no attribute 'pk' #2638
Comments
@zhigang you should really be calling |
@jpadilla : thanks and I think you are right I should override the serializer But it seems the issue alone needs a code fix. Let's keep it open for now. |
Can we reduce this to a more minimal example? |
Code to reproduce it: views.py:
urls.py:
POST to http://127.0.0.1:8000/api/users/ Patch to fix this: #2641 |
OK. I've had a play with this in the shell. This comes up if you call
On this basis I'm going to close this as wrong usage. (Mis-using |
Having looked back at #2637 I have a slight niggle about whether there's some example where you might legitimately want to call My first thought there is "Just remove the field" — i.e. it's an edge-case that the user can handle easily themselves — but if anybody wants to drop a failing test case in here we can look at re-opening again. |
What if we just merge #2641 ? Is that better than just saying: don't do it? |
I faced the same issue when I try to upload an image file to the DRF REST interface. There is no problem when I use 'curl -X POST'. However, when I use angularjs http post service (ajax call), I got the same error message, said function 'get_url()' raised 'obj.pk is none' error.Here is the models.py
Here is the serializers.py
Here is the views.py
|
Unless we have a failing test case that demonstrate the error is on DRF side, there isn't much we can do. |
All these years later, this proved to me massively helpful! Thanks so much. You ended a 2-hour rabbit hole I just spent trying to resolve this. |
Testing code:
Error:
Root cause: there's no pk in the OrderedDict yet at that time.
The text was updated successfully, but these errors were encountered: