-
Notifications
You must be signed in to change notification settings - Fork 771
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
Import of rest_framework backend can fail #567
Comments
Yeah. That's probably right. Fancy doing a PR? |
Sure thing, I'll have it to you shortly. |
There is a problem in that the One possible way to get around this is to add a |
Alternatively, the docs could be updated to include the correct import import django_filters.rest_framework
class ProductFilter(django_filters.rest_framework.FilterSet):
# ... |
I think
Yes. This. |
Why django_filters have references to DRF and Crispy? Both aren't a dependecies. Adapter for DRF should be provided inside DRF or some DRF' plugin/extension. Why? AFAIK django_filter is not an DRF's extension and there are other REST frameworks/libraries.It is not reasonable to include their adapters here. Why DRF is an exception? Same notes for Crispy. |
@marcinn Neither DRF nor Django-Filters depend on each other. There is an optional combined usage. That code used to live in DRF. It now lives in Django-Filters. That's all. Why move? Less surface-area for DRF and easier integration for Django-Filter related fixes. e.g. |
* Try importing `rest_framework` module Fixes #567 * Correct Typo Thanks @kevin-brown!
I'm getting some unexpected behavior around this. I do have DRF installed. But Anyone have an idea what is going on? |
Hmm. No idea at all at first glance. 😐 Can you put a breakpoint in and examine the environment where the import is failing? (Hopefully that reveals more) |
Thanks for a quick response. I'm having a tight deadline right now, but I'll return to the issue when I find some time for this. |
When trying to add django_filters to INSTALLED_APPS in a DRF based project, I get an import issue that doesn't exhibit itself when imported normally. django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. |
@oliver-zhou I guess that it's unlikely to be related to this issue. Most likely you're accessing some model attribute in your FilterSet definition — which is processed at import time before the AppRegistry is initialised. You'll get a traceback. Look through it. That will point to the exact place you're getting the error. Either move the offending line so that it's called at runtime or else (if that's really unavoidable) move the offending definition into your app's I hope that helps. If you're still stuck I suggest posting a question (with the traceback and offending definitions) on StackOverflow. |
@tarkatronic That didn't work for me, still getting error:
|
Changing django-filter in requirements.txt from 1.0.1 to 1.0.0 fixed it for me. |
@osonwanne - That would make sense, since the import was added in the 1.0.1 release. Could you try installing the branch from #741? This shouldn't mask the import error and might give you a useful traceback. |
* Parse rest-framework's version by using more tolerant functions * Factor the way the django-rest-framework's version is parsed * django-rest-framework 3.7 dropped support for django 1.8 * Fix wrong import from rest_framework.filters See: <carltongibson/django-filter#567> * Add tests for regression on #198
Ensure django-filters dependency DRF import happens before filters import attempted. To prevent carltongibson/django-filter#567.
Ensure django-filters dependency DRF import happens before filters import attempted. To prevent carltongibson/django-filter#567.
Ensure django-filters dependency DRF import happens before filters import attempted. To prevent carltongibson/django-filter#567.
In the DRF docs, they give an example which looks like:
This does not work, however, with the way the
django_filters/__init__.py
is set up. Using this example, I get:AttributeError: 'module' object has no attribute 'rest_framework'
I have found a fix for it, by adding the following to
django_filters/__init__.py
:from . import rest_framework
The text was updated successfully, but these errors were encountered: