Skip to content

Avoid AttributeError for PUT and PATCH methods when using APIView #778

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

Merged
merged 12 commits into from
Apr 18, 2020

Conversation

bpleshakov
Copy link
Contributor

@bpleshakov bpleshakov commented Apr 10, 2020

Fixes silenced AttributeError in the case when lookup_url_kwarg doesn't exist in a view

Description of the Change

Checklist

  • PR only contains one change (considered splitting up PR)
  • unit-test added
  • documentation updated
  • CHANGELOG.md updated (only for user relevant changes)
  • author name in AUTHORS

@sliverc
Copy link
Member

sliverc commented Apr 11, 2020

As lookup_field and lookup_url_kwarg are set in GenericAPIView can you give an example in what case a lookup field is actually not set?

@bpleshakov
Copy link
Contributor Author

bpleshakov commented Apr 14, 2020

@sliverc both of these fields aren't set whenever you use default APIView. It is a valid DRF behavior.

UPD: I think I should explain a little bit more. Nothing stops a user to define APIView whatever they want and set DRF-JA JSONParser and JSONRenderer to obtain JSON-API endpoint without an underlying model using some plain serializer. It is not a common case, but we have this usage in our product.

The problem here is that AttributeError you supposed to expect here is caught by DRF request proxy without any notification and unfortunately there is nothing we can do with such behavior.

@codecov
Copy link

codecov bot commented Apr 14, 2020

Codecov Report

Merging #778 into master will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #778      +/-   ##
==========================================
+ Coverage   97.16%   97.21%   +0.04%     
==========================================
  Files          55       55              
  Lines        2825     2874      +49     
==========================================
+ Hits         2745     2794      +49     
  Misses         80       80              
Impacted Files Coverage Δ
example/tests/test_parsers.py 100.00% <100.00%> (ø)
rest_framework_json_api/parsers.py 97.43% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f19ef0...fc9c390. Read the comment docs.

Copy link
Member

@sliverc sliverc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Could you follow up by adding a test and changelog entry then? Thanks.

@sliverc sliverc changed the title 409 conflict on different ids works with bug 409 conflict on different ids when using APIView Apr 14, 2020
@bpleshakov bpleshakov requested a review from sliverc April 14, 2020 12:26
Copy link
Member

@sliverc sliverc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This looks good.

@sliverc sliverc changed the title 409 conflict on different ids when using APIView Avoid AttributeError for PUT and PATCH methods when using APIView Apr 18, 2020
@sliverc sliverc merged commit ff0f93a into django-json-api:master Apr 18, 2020
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 this pull request may close these issues.

3 participants