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 behavior of select().eq("column", None) #403

Closed
st-pasha opened this issue Apr 4, 2024 · 2 comments
Closed

Incorrect behavior of select().eq("column", None) #403

st-pasha opened this issue Apr 4, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@st-pasha
Copy link

st-pasha commented Apr 4, 2024

Bug report

Describe the bug

If a table contains a nullable column, then trying to use that column in a filter via .eq(column, None) produces rows where the column has text "None" (instead of matching NULL values); and using .is_(column, None) produces an error "failed to parse filter (is.None)".

To Reproduce

Create a simple table "tmp" with a nullable column "text" of type text:

create table public.tmp (
    id bigint generated by default as identity,
    text text null,
    constraint tmp_pkey primary key (id)
  ) tablespace pg_default;

Insert records:

insert into tmp(text) values("None");
insert into tmp(text) values(NULL);

Query the table via the python client:

import supabase
client = supabase.create_client(...)

response = client.table("tmp").select("*").eq("text", None)
print(response.data)

Expected behavior

Actual behavior: Row 1 is returned (where the text is "None"),
Expected behavior: Row 2 is returned (where the text is NULL).

System information

supabase.__version__: 2.4.1

Additional context

Can be fixed by redefining the function eq() in BaseFilterRequestBuilder as follows:

    def eq(self, column: str, value: Any) -> Self:
        if value is None:
            value = "NULL"
            op = Filters.IS
        else:
            op = Filters.EQ
        return self.filter(column, op, value)
@st-pasha st-pasha added the bug Something isn't working label Apr 4, 2024
@sapphire008
Copy link
Contributor

According to the Python doc, this is how null checking is achieved: https://supabase.com/docs/reference/python/is

data, count = supabase.table('countries')
  .select('*')
  .is_('name', 'null')
  .execute()

@silentworks
Copy link
Contributor

As @sapphire008 has stated you should use the is_ method with null. I have opened a PR to add support for Python's None type with the is_ method. #446

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants