Skip to content
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

server error if update_lookup_field is missing from the provided data #34

Closed
flc opened this issue Apr 25, 2015 · 3 comments · Fixed by #35
Closed

server error if update_lookup_field is missing from the provided data #34

flc opened this issue Apr 25, 2015 · 3 comments · Fixed by #35

Comments

@flc
Copy link

flc commented Apr 25, 2015

a 400 bad request would be much better.

I think it's because id_field.get_value(data) here https://github.com/miki725/django-rest-framework-bulk/blob/master/rest_framework_bulk/drf3/serializers.py#L26 returns an rest_framework.fields.empty object.

versions:
djangorestframework==3.1.1
djangorestframework-bulk==0.2

Traceback (most recent call last):
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/rest_framework/viewsets.py", line 85, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/rest_framework/views.py", line 452, in dispatch
    response = self.handle_exception(exc)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/rest_framework/views.py", line 449, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/rest_framework_bulk/drf3/mixins.py", line 79, in partial_bulk_update
    return self.bulk_update(request, *args, **kwargs)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/rest_framework_bulk/drf3/mixins.py", line 74, in bulk_update
    self.perform_bulk_update(serializer)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/rest_framework_bulk/drf3/mixins.py", line 85, in perform_bulk_update
    return self.perform_update(serializer)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/rest_framework/mixins.py", line 73, in perform_update
    serializer.save()
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 598, in save
    self.instance = self.update(self.instance, validated_data)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/rest_framework_bulk/drf3/serializers.py", line 51, in update
    '{}__in'.format(id_attr): all_validated_data_by_id.keys(),
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/db/models/query.py", line 679, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/db/models/query.py", line 697, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1301, in add_q
    clause, require_inner = self._add_q(where_part, self.used_aliases)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1328, in _add_q
    current_negated=current_negated, connector=connector, allow_joins=allow_joins)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1200, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1096, in build_lookup
    return final_lookup(lhs, rhs)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/db/models/lookups.py", line 96, in __init__
    self.rhs = self.get_prep_lookup()
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/db/models/lookups.py", line 134, in get_prep_lookup
    return self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs)
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 729, in get_prep_lookup
    return [self.get_prep_value(v) for v in value]
  File "/home/flc/.virtualenvs/drfbulktest/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 985, in get_prep_value
    return int(value)
TypeError: int() argument must be a string or a number, not 'classobj'```
miki725 added a commit that referenced this issue Apr 26, 2015
@miki725
Copy link
Owner

miki725 commented Apr 26, 2015

@flc thank you for the report. DRF-bulk. 0.2.1 has the fix. please let me know if you will have any more issues

@flc
Copy link
Author

flc commented Apr 28, 2015

thanks for the quick fix!

blackrobot pushed a commit to HowGood/django-rest-framework-bulk that referenced this issue Nov 4, 2015
@rtindru
Copy link

rtindru commented Dec 15, 2016

@miki725 Can you help me understand the fix please? How is raising a validation error a fix for this issue?
HowGood@fa1e9fa

As a followup - can I do a bulk create or update using django-rest-framework-bulk? The code seems to suggest that they need to be done independently - only creates happen with the BulkCreateModelMixin and only updates happen with the BulkUpdateModelMixin. Is this correct - is there no way to have both new objects and updates happen via the same view/serializer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants