Comments (6)
@clokep I created #97 pull request to fix this issue, please kindly check it. Thank you.
from django-querysetsequence.
Hmm, I wonder if this doesn't work for any nullable field? Definitely seems like an oversight, thanks for the bug report!
Do you have a fuller stack trace of the error? I suspect some special handling is needed near:
But I'm not 100% sure.
from django-querysetsequence.
Yes, You're right. This is the full stack trace for it.
Environment:
Request Method: GET
Request URL: http://localhost:8000/api/calls2/?sort=brand
Django Version: 3.2.11
Python Version: 3.8.13
Installed Applications:
['django.contrib.admindocs',
'server.apps.ServerConfig',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'zappa_django_utils',
'pushevent.apps.PushEventConfig',
'rest_framework.authtoken',
'guardian',
'django_filters',
'drf_spectacular',
'imagekit',
'reservations',
'questionnaires',
'django.contrib.admin',
'oauth2_provider',
'social_django',
'rest_framework_social_oauth2',
'authentication.apps.AuthenticationConfig',
'monotonic_counter.apps.MonotonicCounterConfig',
'parler',
'anymail',
'ordered_model',
'dynamo_cache',
'drf_multiple_model',
'django.contrib.humanize',
'puml_generator',
'debug_toolbar',
'channels',
'channels_websocket.apps.ChannelsWebsocketConfig']
Installed Middleware:
['debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'server.permissions.StandardiseErrorMiddleware',
'server.permissions.MissingTOSAgreementResponseMiddleware']
Traceback (most recent call last):
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/rest_framework/viewsets.py", line 125, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/rest_framework/mixins.py", line 40, in list
page = self.paginate_queryset(queryset)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/rest_framework/generics.py", line 171, in paginate_queryset
return self.paginator.paginate_queryset(queryset, self.request, view=self)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/rest_framework/pagination.py", line 216, in paginate_queryset
return list(self.page)
File "/opt/homebrew/Cellar/[email protected]/3.8.13/Frameworks/Python.framework/Versions/3.8/lib/python3.8/_collections_abc.py", line 874, in __iter__
v = self[i]
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/django/core/paginator.py", line 188, in __getitem__
self.object_list = list(self.object_list)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/queryset_sequence/__init__.py", line 549, in __iter__
self._fetch_all()
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/queryset_sequence/__init__.py", line 526, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/queryset_sequence/__init__.py", line 197, in _ordered_iterator
iterables = sorted(iterables, key=comparator)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/queryset_sequence/__init__.py", line 181, in comparator
return _comparator(tuple_1[2], tuple_2[2])
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/queryset_sequence/__init__.py", line 136, in comparator
return cls._cmp(v1, v2) * reverses[0]
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/queryset_sequence/__init__.py", line 101, in _cmp
return cmp(value1, value2)
File "/Users/vuongdo/Library/Caches/pypoetry/virtualenvs/livecall-5JrKXylz-py3.8/lib/python3.8/site-packages/queryset_sequence/__init__.py", line 26, in cmp
return (a > b) - (a < b)
Exception Type: TypeError at /api/calls2/
Exception Value: '>' not supported between instances of 'str' and 'NoneType'
from django-querysetsequence.
I think that code needs special handling for null
, unfortunately not all databases order null
the same way, but pretty much we would want to return 1
is value1
is None
and -1
if value2
is None
(or perhaps the opposite depending how you want nulls sorted). (And maybe 0
if they're both null
.)
from django-querysetsequence.
I'm currently using PostgreSQL, and look like your above-defined rule is the default of Postgres sorting with null. Please fixed it as you mention. Thank you.
For more improvements, you probably want to add nulls_last
and nulls_first
when you implement this update #92
from django-querysetsequence.
I'm currently using PostgreSQL, and look like your above-defined rule is the default of Postgres sorting with null.
It should work on everything except SQLite, I think.
Please fixed it as you mention. Thank you.
I unfortunately won't have time to implement this anytime soon, but would appreciate a pull request for it! Let me know if you have any questions!
For more improvements, you probably want to add
nulls_last
andnulls_first
when you implement this update #92
Good catch! 👍
from django-querysetsequence.
Related Issues (20)
- Retrieving related values doen't work after order_by() HOT 3
- Need help! How to pass the serializers with the QuerySetSequence? HOT 2
- Slicing issue HOT 6
- DJ1.10: TypeError: not_impl() got an unexpected keyword argument 'using' HOT 4
- NotImplementedError: QuerySequence does not implement get_compiler() HOT 8
- Implement distinct() HOT 8
- 'QuerySetSequence' object has no attribute '_cloning' HOT 3
- Using QuerySets from different databases is not supported HOT 7
- Broken support for DjangoFilterBackend?
- New Version HOT 3
- Support Django 3.0 ( / drop support for Django 1.11 / Python 2.7) HOT 5
- SyntaxWarning: "is not" with a literal. Did you mean "!="? HOT 6
- pip installing this package is still using django.utils import six HOT 1
- 'QuerySetSequence' object has no attribute 'query' HOT 1
- AttributeError: 'QuerySetSequence' object has no attribute '_prefetch_related_lookups' HOT 10
- Support using `models.F` in `QuerySetSequence.order_by()` HOT 1
- Support asynchronous ORM methods
- Support Django 4.1 fields for `bulk_create()`
- Support prefetching in `iterator()`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-querysetsequence.