-
Notifications
You must be signed in to change notification settings - Fork 106
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
AttributeError: 'QuerySet' object has no attribute 'pk' when doing bulk update #68
Comments
Already a little dated, but since I stumbled upon the same problem when trying to implement bulk actions myself I thought that I could shed some light onto this. self.child.instance = self.instance.get(id=item['id'])
self.child.initial_data = item
validated = self.child.run_validation(item) |
Thanks for your reply! I'm still a bit stuck however... I've tried creating an
I'm now getting an error related to the fact that the serializer's instance is None.
Forgive me if I'm overlooking something really stupid :) |
Yeah, that's something I came across this morning as well. The code did not account for creations where there are no existing instances (which you are probably trying to do there). # prepare child serializer to only handle one instance
self.child.instance = self.instance.get(id=item['id']) if self.instance else None
self.child.initial_data = item
validated = self.child.run_validation(item) |
Thanks! You should try and get this in a PR. I had to add
to my model serializer because it's a |
Good to hear that it works for you. If I find a minute, I'll create that PR. But seeing that the repo owner is not too active around here it might not be worth it. |
for me i was imported BulkSerializerMixin, BulkListSerializer from, but actually it should be from, |
@LaundroMat Your code works like a charm with the edit of @calmez |
Heya - hitting this just now too, would absolutely love if this was fixed or docs were updated to mention that this is broken atm! |
Ah but this project seems abandoned. Sad! |
fixed child instance miki725#68
Thank you very much for the AdaptedBulkListSerializer @calmez. |
@jonbesga You're very welcome. 😄 I guess this is one of these nice moments with FOSS that keeps us all sharing our work 👍 Loving it |
Thanks for the AdaptedSerializerMixin @calmez and @LaundroMat. Late to the game but... I can update multiple fields with this, that's right. If I try to add a create a new object, by passing it in the list (without id) I get an 'Internal server error 'id''. If I try to delete them, like, sending an array with one object in it (whereas I had multiple objects in this list), the serializer returns correct data, however this is not saved correctly to the database, nothing is removed. Or this should work it like that? And I can't delete or create in one method? Thanks! |
Sorry @radokristof, but I haven't been using DRF for a long time now and I don't have the time to pick it up again. |
@LaundroMat Thanks for your response! I fairly new to Django but what I was able to figure out is that it works (with your code) the way it should work or I might be wrong. |
I had this error, for the ones coming here from Google, my problem was this one: The model I wanted to serialize had a field containing |
When trying to PATCH with a list of dicts, I'm getting this error:
Relevant code:
POSTing data works fine, by the way, it's only PATCH that generates this error.
I'm using
The text was updated successfully, but these errors were encountered: