Empty string equality expression transpiles to an always-false query in Django + Oracle
Closed this issue · 2 comments
Describe the bug
Expressions involving an equality operator and an empty string always evaluate to false
when using Django + Oracle. This seems to be specific to the Django transpiler.
To Reproduce
Here's a test case that reproduces this behavior:
import pytest
from django.contrib.auth.models import User
from scim2_filter_parser.transpilers.django_q_object import get_query
@pytest.mark.django_db
def test_filter_empty_string_fails() -> None:
user = User(username='dummy_username', first_name='')
user.save()
query = get_query(
'name.givenName eq ""', {('name', 'givenName', None): 'first_name'}
)
assert list(User.objects.filter(query)) == [user]
Which fails with:
tl;dr: The query returns no results
> assert list(User.objects.filter(query)) == [user]
E assert [] == [<User: dummy_username>]
E
E Right contains one more item: <User: dummy_username>
E
E Full diff:
E + []
E - [
E - <User: dummy_username>,
E - ]
The generated query is:
SELECT
"AUTH_USER"."ID", "AUTH_USER"."PASSWORD", "AUTH_USER"."LAST_LOGIN", "AUTH_USER"."IS_SUPERUSER", "AUTH_USER"."USERNAME", "AUTH_USER"."FIRST_NAME", "AUTH_USER"."LAST_NAME", "AUTH_USER"."EMAIL", "AUTH_USER"."IS_STAFF", "AUTH_USER"."IS_ACTIVE", "AUTH_USER"."DATE_JOINED"
FROM "AUTH_USER"
WHERE UPPER("AUTH_USER"."FIRST_NAME") = UPPER('')
Expected behavior
The generated query should find dummy_username
.
Environment:
Python version: 3.11.7
Django version: 4.2.12
scim-filter-parser version: 0.5.1
Additional context
According to this article (and my own tests via sqlplus
), UPPER("AUTH_USER"."FIRST_NAME") = UPPER('')
will always evaluate to false
, even when "AUTH_USER"."FIRST_NAME"
is an empty string.
Thank you for this bug report! Unfortunately, we have a very low capacity work on this at the moment. I am happy to review PRs if you would like to make this change to support Oracle.
No worries! I got a proposal for a PR we can start with. I'll open it as soon as I have some free time.