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

make QuerySet.exclude() range lookup exclude data with a null boundary #143

Conversation

WaVEV
Copy link
Collaborator

@WaVEV WaVEV commented Sep 27, 2024

No description provided.

@timgraham
Copy link
Collaborator

I wonder about the behavior when an endpoint is null. Example:

queryset = SimulationRun.objects.filter(
    midpoint__range=[F("start__time"), None]
)
self.assertSequenceEqual(queryset, [])

On SQLite and PostgreSQL, the SQL WHERE "midpoint" BETWEEN "time" AND NULL returns no results.

With this patch, MongoDB returns [s1, s2].

But I'm not sure if this is a valid use case since Django doesn't document or test it. And actually, MongoDB's results seem reasonable if you interpret range=[F("start__time"), None] as meaning "give me values from the start time to the end of all time".

@WaVEV
Copy link
Collaborator Author

WaVEV commented Sep 27, 2024

I wonder about the behavior when an endpoint is null. Example:

queryset = SimulationRun.objects.filter(
    midpoint__range=[F("start__time"), None]
)
self.assertSequenceEqual(queryset, [])

On SQLite and PostgreSQL, the SQL WHERE "midpoint" BETWEEN "time" AND NULL returns no results.

With this patch, MongoDB returns [s1, s2].

But I'm not sure if this is a valid use case since Django doesn't document or test it. And actually, MongoDB's results seem reasonable if you interpret range=[F("start__time"), None] as meaning "give me values from the start time to the end of all time".

Well, I misunderstood it. I thought that None allows us to get values from the start time to the end of all time.

@timgraham
Copy link
Collaborator

It might be fine. I found that at least for Microsoft's SQL: "If any input to the BETWEEN or NOT BETWEEN predicate is NULL, the result is UNKNOWN."

@timgraham timgraham changed the title Fix range lookup includes incorrect values. make QuerySet.exclude() range lookup exclude data with a null boundary Sep 27, 2024
@WaVEV
Copy link
Collaborator Author

WaVEV commented Sep 27, 2024

It might be fine. I found that at least for Microsoft's SQL: "If any input to the BETWEEN or NOT BETWEEN predicate is NULL, the result is UNKNOWN."

"While it is a valid definition, the issue is in how we handle Null or None values. I don't believe this change fixes the test I mean the functionality.

@timgraham
Copy link
Collaborator

What I mean is that I'm not sure we have to match the behavior on SQLite/PostgreSQL, since the expected result isn't well-defined by the SQL standard.

@WaVEV WaVEV force-pushed the bugfix-range-lookup-includes-incorrect-values branch from 4ae108b to 6039d93 Compare October 3, 2024 04:20
@WaVEV WaVEV force-pushed the bugfix-range-lookup-includes-incorrect-values branch from 6039d93 to 5f64c22 Compare October 3, 2024 04:24
@timgraham timgraham merged commit 5c29684 into mongodb-labs:main Oct 3, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants