Hi,
I just updated to Django 2.1 from Django 2.0.7 using django-tastypie==0.14.1
on python 3.5 and ran into this error:
...
File "<frozen importlib._bootstrap_external>", line 673, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/var/www/brownpapersession/dev/brownpapersession/brownpapersession/urls.py", line 16, in <module>
from tastypie.api import Api, NamespacedApi
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-packages/tastypie/api.py", line 11, in <module>
from tastypie.resources import Resource
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-packages/tastypie/resources.py", line 32, in <module>
from django.db.models.sql.constants import QUERY_TERMS
ImportError: cannot import name 'QUERY_TERMS'
I'll see if I can find more information on QUERY_TERMS
The message disappears after changing resource.py
to this:
try:
from django.db.models.sql.constants import QUERY_TERMS
except ImportError:
# Django 2.1
QUERY_TERMS = {
'exact', 'iexact', 'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in',
'startswith', 'istartswith', 'endswith', 'iendswith', 'range', 'year',
'month', 'day', 'week_day', 'hour', 'minute', 'second', 'isnull', 'search',
'regex', 'iregex',
}
I'll try to create a PR later on
It usually takes a few weeks to implement full compatibility for a new release of Django.
For this one issue, QUERY_TERMS
was probably moved; rather than re-implementing it, we should figure out the new right way to get a list of sql terms the ORM supports.
Looks like QUERY_TERMS
is removed.
This is turning into a fairly difficult problem to solve; tastypie was relying heavily on QUERY_TERMS
to quickly pre-validate filters. There doesn't appear to be a graceful way to regenerate that set of operators without overhauling ModelResource.build_filters
. This is long overdue, anyway; validating against a constant list of operators made it impossible to add more operators without monkey-patching, and the global list of operators meant it would allow nonsensical operations through for fields that make no sense, like a case-insensitive filter on an integer field.
The path forward is probably refactoring build_filters
to retrieve the Django field and use the new lookups api to validate the operation.
This was fixed in #1564 and merged into the django-2.1
branch. That branch isn't ready for release due to other test failures (see #1562), but I've confirmed that the remaining test failures are unrelated to QUERY_TERMS
so this issue can be closed.
To avoid further confusion, I'll leave this issue open until the rest of 2.1 support is implemented and merged to master.
The test suite is now passing under Django 2.1. I'll release to PyPI on 9/3 if no major bugs are found before then.
This will also drop support for Django 1.8, which was EOL'd back in April.
Released today.
Appears to be working fine, @georgedorn Thanks!
Most helpful comment
This was fixed in #1564 and merged into the
django-2.1
branch. That branch isn't ready for release due to other test failures (see #1562), but I've confirmed that the remaining test failures are unrelated toQUERY_TERMS
so this issue can be closed.