Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The Python-style is_null() filter does not exist

See original GitHub issue

Describe the bug

The documentation states:

isnull: not null can be written as

But this does not actually seem to work.

To Reproduce

$ python --version
Python 3.9.1

$  pip freeze

Try to run this script with uvicorn main:app:

from typing import List, Optional

import databases
import sqlalchemy
from fastapi import FastAPI

import ormar

app = FastAPI()
metadata = sqlalchemy.MetaData()
database = databases.Database("sqlite:///test.db")
app.state.database = database

class Item(ormar.Model):
    class Meta:
        tablename = "items"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    name: Optional[str] = ormar.String(nullable=True, max_length=100)

async def startup() -> None:
    engine = sqlalchemy.create_engine(str(database.url))

    await database.connect()

    for _ in range(100):
        await Item.objects.create(name="Name")

async def shutdown() -> None:
    database_ = app.state.database
    if database_.is_connected:
        await database_.disconnect()

@app.get("/items/", response_model=List[Item])
async def get_items():
    items = await Item.objects.filter(
    return items

Error when run:

$ uvicorn main3:app --reload
INFO:     Uvicorn running on (Press CTRL+C to quit)
INFO:     Started reloader process [63484] using statreload
INFO:     Started server process [63487]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO: - "GET /docs HTTP/1.1" 200 OK
INFO: - "GET /openapi.json HTTP/1.1" 200 OK
INFO: - "GET /items/ HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "./venv/lib/python3.9/site-packages/uvicorn/protocols/http/", line 396, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "./venv/lib/python3.9/site-packages/uvicorn/middleware/", line 45, in __call__
    return await, receive, send)
  File "./venv/lib/python3.9/site-packages/fastapi/", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "./venv/lib/python3.9/site-packages/starlette/", line 111, in __call__
    await self.middleware_stack(scope, receive, send)
  File "./venv/lib/python3.9/site-packages/starlette/middleware/", line 181, in __call__
    raise exc from None
  File "./venv/lib/python3.9/site-packages/starlette/middleware/", line 159, in __call__
    await, receive, _send)
  File "./venv/lib/python3.9/site-packages/starlette/", line 82, in __call__
    raise exc from None
  File "./venv/lib/python3.9/site-packages/starlette/", line 71, in __call__
    await, receive, sender)
  File "./venv/lib/python3.9/site-packages/starlette/", line 566, in __call__
    await route.handle(scope, receive, send)
  File "./venv/lib/python3.9/site-packages/starlette/", line 227, in handle
    await, receive, send)
  File "./venv/lib/python3.9/site-packages/starlette/", line 41, in app
    response = await func(request)
  File "./venv/lib/python3.9/site-packages/fastapi/", line 201, in app
    raw_response = await run_endpoint_function(
  File "./venv/lib/python3.9/site-packages/fastapi/", line 148, in run_endpoint_function
    return await**values)
  File "./", line 46, in get_items
    items = await Item.objects.filter( .is_null(False)).all()
  File "./venv/lib/python3.9/site-packages/ormar/queryset/", line 46, in __getattr__
    return object.__getattribute__(self, item)  # pragma: no cover
AttributeError: 'FieldAccessor' object has no attribute 'is_null'

Expected behavior

Query to complete successfully and filter out Items with null name.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

collerekcommented, Apr 22, 2021

Thanks, that means a lot 😃 Try to build a community around ormar to get more people to test/contribute but it’s going super slow 😃 Anyway, docs typo fixed.

collerekcommented, Apr 22, 2021

Yeah there is a problem with dynamic attributes typing and autocompletion in ormar, there is a plugin for pydantic (, and I am thinking about forking it and creating one for ormar that hacks around autocompletion, but since I don’t know kotlin and didn’t write java in years (not to mention never created pycharm plugin) it’s gonna take a while 😁

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to filter NaT using isnull() - python - Stack Overflow
I have dataframe where one column has significant no. of Nat. I'm using isnull() to filter them but it does not seem to...
Read more >
python pandas filter operations and operator or isnull not is null
It can be observed that there are two records where the Open values are null as shown in figure 6. Figure 6: Using...
Read more >
Filtering and sorting data - ormar
Python style filters ... So operations like filter() , select_related() , limit() and offset() etc. can be chained. ... Note that you do...
Read more >
Python Pandas filter operations and operator or isnull not is null
In this video we will see how to apply filter conditions on multiple columns using AND , OR operators.Also we will see how...
Read more >
PySpark isNull() & isNotNull() - Spark by {Examples}
isNotNull – PySpark isNotNull() method returns True if the current expression is NOT NULL/None. This function is only present in the Column class...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found