mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-15 00:02:17 -06:00
Fixes #18900: raise QuerySetNotOrdered exception when trying to paginate unordered API querysets (#19943)
* Fixes #18900: introduce/raise QuerySetNotOrdered exception Defines a new exception, `QuerySetNotOrdered`, and raises it in `OptionalLimitOffsetPagination.paginate_queryset` in the right conditions: - the iterable to be paginated is a QuerySet isinstance - the `queryset.ordered` flag is not truthy * Don't try to reapply ordering if ordering is already present * Add ordering for failing tagged-objects list API endpoint I chose to implement this here for TaggedItemViewSet, rather than on the model, because any meaningful ordering is going to be done on the related Tag instance and I didn't want to introduce potential, not well understood side-effects by applying a model-wide ordering via a related model field. * Add default Token ordering behavior * Adds basic tests for raising QuerySetNotOrdered * Note why ordering is not applied in TaggedItem.Meta
This commit is contained in:
@@ -74,6 +74,7 @@ class Token(models.Model):
|
||||
class Meta:
|
||||
verbose_name = _('token')
|
||||
verbose_name_plural = _('tokens')
|
||||
ordering = ('-created',)
|
||||
|
||||
def __str__(self):
|
||||
return self.key if settings.ALLOW_TOKEN_RETRIEVAL else self.partial
|
||||
|
||||
Reference in New Issue
Block a user