Skip to content

Fix for apps that don't load contenttypes module. #345

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 1 commit into from
May 7, 2017

Conversation

amw
Copy link
Contributor

@amw amw commented May 7, 2017

PR #319 brought support for generic relations. Unfortunately apps that don't add contenttypes to it's INSTALLED_APPS would crash and burn:

RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

I would like to add a test for this, but it would require two separate Django configs. Not sure how you would want to handle that in py.test.

Also using type(something) is object() comparison as a safer alternative to type(something) is type(None). If something happened to be None we would enter a branch that was never supposed to run.

@codecov-io
Copy link

codecov-io commented May 7, 2017

Codecov Report

Merging #345 into develop will increase coverage by <.01%.
The diff coverage is 80%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #345      +/-   ##
===========================================
+ Coverage    76.37%   76.38%   +<.01%     
===========================================
  Files           50       50              
  Lines         6024     6025       +1     
===========================================
+ Hits          4601     4602       +1     
  Misses        1423     1423
Impacted Files Coverage Δ
rest_framework_json_api/utils.py 89.79% <80%> (+0.04%) ⬆️

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 da97874...20933e6. Read the comment docs.

@mblayman
Copy link
Collaborator

mblayman commented May 7, 2017

I agree that a test would be nice, but this might be one of those cases where the setup for that test would be extreme overkill since it involves things that happen at import time.

What do you think of adding a # pragma: no cover to the if clause that checks for contenttypes in INSTALLED_APPS? It seems like that might be a clue to future readers that this was considered and declared "not worth testing."

PR django-json-api#319 brought support for generic relations. Unfortunately apps that
don't add contenttypes to it's INSTALLED_APPS would crash and burn:

```
RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
```

Also using `type(something) is object()` comparison as a safer
alternative to `type(something) is type(None)`. If `something` happened
to be `None` we would enter a branch that was never supposed to run.
@amw amw force-pushed the fix-no-contenttypes branch from 36b0c58 to 20933e6 Compare May 7, 2017 17:50
@amw
Copy link
Contributor Author

amw commented May 7, 2017

Added.

@mblayman mblayman merged commit 89779c4 into django-json-api:develop May 7, 2017
@mblayman
Copy link
Collaborator

mblayman commented May 7, 2017

👍

@amw amw deleted the fix-no-contenttypes branch May 31, 2017 13:49
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