Skip to content
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

Ensure CursorPagination respects nulls in the ordering field #8912

Merged
merged 9 commits into from Apr 8, 2023

Conversation

ddelange
Copy link
Contributor

Note: Before submitting this pull request, please review our contributing guidelines.

Description

When some records contain a null for the ordering field:

  • 1.year = null
  • 2.year = null
  • 3.year = 1995
  • 4.year = 2000

Currently, if we cursor paginate with ?page_size=1&ordering=-year (the nulls will come first), we'll paginate: 1, 4, 3.

Expected behaviour: 1, 2, 4, 3.

The problem lies in the __lt/__gt filter, which implicitly filters out nulls altogether.

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please make sure that the tests also pass and no regression introduced?

@ddelange
Copy link
Contributor Author

ddelange commented Mar 20, 2023

Hi @auvipy 👋

I saw the MockQuerySet (tests/test_pagination.py) related errors introduced by this PR, I will look into it soon.

There are also a number of errors that do not look related to this PR (isoformat datetime discrepancies etc). Could you have a look?

@auvipy
Copy link
Member

auvipy commented Mar 20, 2023

the CI is stable in main branch, if you fiix it, I can look into the others for sure. btw which issue you are trying to fix?

@ddelange
Copy link
Contributor Author

I haven't created an issue for this PR. Would you like me to create one?

the CI is stable in main branch

ok interesting, that these can be side-effects of this PR 🤔

_____________________ TestNaiveDateTimeField.test_outputs ______________________
tests/test_fields.py:674: in test_outputs
    assert self.field.to_representation(output_value) == expected_output, \
E   AssertionError: output value: datetime.datetime(2001, 1, 1, 13, 0)
E   assert '2001-01-01T13:00:00-06:00' == '2001-01-01T13:00:00'
E     - 2001-01-01T13:00:00
E     + 2001-01-01T13:00:00-06:00
E     ?                    ++++++
_________________ TestRegularFieldMappings.test_field_options __________________
tests/test_model_serializer.py:219: in test_field_options
    self.assertEqual(repr(TestSerializer()), expected)
E   AssertionError: "Test[316 chars]rue, max_value=9223372036854775807, min_value=[491 chars]')))" != "Test[316 chars]rue, required=False)\n    default_field = Inte[302 chars]')))"
E   Diff is 1073 characters long. Set self.maxDiff to None to see it.

@auvipy
Copy link
Member

auvipy commented Mar 20, 2023

you can describe that in description section too. and yes those are side-effects of this PR

@ddelange
Copy link
Contributor Author

you can describe that in description section too

what exactly would you like me to add to the current description of the bug?

@ddelange
Copy link
Contributor Author

yes those are side-effects of this PR

both tests/test_fields.py and tests/test_model_serializer.py are green on this branch locally btw (mac w/ cpython 3.11) 🤔

@ddelange
Copy link
Contributor Author

I haven't created an issue for this PR. Would you like me to create one?

the CI is stable in main branch

ok interesting, that these can be side-effects of this PR 🤔

_____________________ TestNaiveDateTimeField.test_outputs ______________________
tests/test_fields.py:674: in test_outputs
    assert self.field.to_representation(output_value) == expected_output, \
E   AssertionError: output value: datetime.datetime(2001, 1, 1, 13, 0)
E   assert '2001-01-01T13:00:00-06:00' == '2001-01-01T13:00:00'
E     - 2001-01-01T13:00:00
E     + 2001-01-01T13:00:00-06:00
E     ?                    ++++++
_________________ TestRegularFieldMappings.test_field_options __________________
tests/test_model_serializer.py:219: in test_field_options
    self.assertEqual(repr(TestSerializer()), expected)
E   AssertionError: "Test[316 chars]rue, max_value=9223372036854775807, min_value=[491 chars]')))" != "Test[316 chars]rue, required=False)\n    default_field = Inte[302 chars]')))"
E   Diff is 1073 characters long. Set self.maxDiff to None to see it.

found out these errors also occur on master, they just don't fail tox overall 👍

@ddelange
Copy link
Contributor Author

I fixed the existing pagination tests, will add a new test that covers nulls in the ordering field.

@auvipy
Copy link
Member

auvipy commented Mar 23, 2023

thanks, and will be looking forward to more relevant tests

@auvipy auvipy requested a review from a team April 8, 2023 10:34
@auvipy auvipy added this to the 3.15 milestone Apr 8, 2023
@auvipy auvipy added the Bug label Apr 8, 2023
@auvipy auvipy merged commit b1cec51 into encode:master Apr 8, 2023
7 checks passed
@ddelange
Copy link
Contributor Author

hi @auvipy 👋 any chance you could cut a new release any time soon?

@auvipy
Copy link
Member

auvipy commented Jun 19, 2023

I'm waiting for Original creators response. I hope that will happen soon

auvipy pushed a commit that referenced this pull request Apr 27, 2024
@auvipy
Copy link
Member

auvipy commented Apr 27, 2024

we have to revert this for some issues

@ddelange
Copy link
Contributor Author

thanks for the ping, #9381 makes total sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants