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

Incorrect handling of None in 'in' operator for status field #728

Open
megashurik opened this issue Oct 9, 2024 · 0 comments
Open

Incorrect handling of None in 'in' operator for status field #728

megashurik opened this issue Oct 9, 2024 · 0 comments

Comments

@megashurik
Copy link

megashurik commented Oct 9, 2024

Description:
We've discovered an issue with Pony ORM where the 'in' operator doesn't correctly handle None values in certain queries. Specifically, when querying for a status field that can be either an empty string, None, or a specific value, the query fails to return records where the status is None.

Steps to reproduce:

  1. Create a database with a table that has a nullable status field.

  2. Insert a record with status set to None.

  3. Run the following query:

    Tasks.select(lambda t: t.status in ('', None, 'main')).count()

Expected behavior:
The query should return records where status is an empty string, None, or 'main'.

Actual behavior:
The query doesn't return records where status is None.

Workaround:
The issue can be worked around by expanding the condition:

Tasks.select(lambda t: t.status == '' or t.status == None or t.status == 'main').count()

This query correctly returns records with None status.

Environment:

  • Pony ORM version: 0.7.19
  • Python version: 3.10.11
  • Database backend: PostgreSQL
  • Operating System: Ubuntu Server 22.04

Additional notes:
This behavior is inconsistent with Python's standard 'in' operator, where None in (None, '', 'main') returns True.

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

No branches or pull requests

1 participant