AttributeError 'NoneType' object has no attribute '_from_objects' persistent exception #9666
Replies: 6 comments 13 replies
-
hi - re: "We are not able to reproduce this regularly but when it happens it impacts all requests coming into a running instance of our application and never recovers." this seems like a race condition of some kind, such as your modules are still being imported when part of the program starts serving requests. The NoneType refers to getting a None into the "_raw_columns" collection of a Select which is not possible without some kind of invalid state elsewhere. We get many, many...many......MANY people using FastAPI who have race-condition related issues. I would ensure all modules are fully imported and registry.configure is called, before any threads/tasks/greenlets/subprocesses start spinning up, however fastAPI has you configure that. I'd reach out to FastAPI for more help. |
Beta Was this translation helpful? Give feedback.
-
I added a call to |
Beta Was this translation helpful? Give feedback.
-
The error persists even after calling |
Beta Was this translation helpful? Give feedback.
-
same issue reported at https://groups.google.com/g/sqlalchemy/c/uVabm2B_Emw/m/xX1RJjWlBgAJ?utm_medium=email&utm_source=footer anything look familiar in that message? |
Beta Was this translation helpful? Give feedback.
-
OK we now have a codepath that explains "'NoneType' object has no attribute '_from_objects'" and you likely have the same issue as the poster. however, I dont know how to reproduce it. But, one patch that would naively solve this, if you could try it, is this: diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index 8e06c4f598..2bac1aad48 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -218,10 +218,10 @@ class ColumnLoader(LoaderStrategy):
if adapter:
if check_for_adapt:
c = adapter.adapt_check_present(c)
- if c is None:
- return
else:
c = adapter.columns[c]
+ if c is None:
+ return
compile_state._append_dedupe_col_collection(c, column_collection) |
Beta Was this translation helpful? Give feedback.
-
I've started #9777 where I have a patch that simplifies part of the JoinedLoader, in an area that seems a reasonable place to guess that this issue might be arising from. the patch is the review at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4615 and while I can't pinpoint exactly what's happening, this patch removes a whole knot where a risky thread-sensitive thing was going on and just simplifies it to not do that. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
We get an unexpected exception when attempting to query our database that seems to put SQLAlchemy into some kind of broken state from which it cannot recover. We are not able to reproduce the issue regularly but when it does happen the instance of the application in question cannot run any queries without generating this exception and will never recover. The queries are fairly innocuous such as:
The only pattern we have seen is that it always happens at startup as in the container will exhibit the exception from the very first request it receives and then fail onwards from that point on for all requests using the database and it does not seem that containers that successfully start up and serve requests ever run into this problem after they succeed the first time. This seems to point to some kind of initialization issue or maybe some part of the initialization code not being thread safe.
Sorry there is not more detail here, have been unable to reproduce this despite a lot of attempts
Optional link from https://docs.sqlalchemy.org which documents the behavior that is expected
No response
SQLAlchemy Version in Use
2.0.4
DBAPI (i.e. the database driver)
psycopg2
Database Vendor and Major Version
PostgreSQL 14 (via AlloyDB on GCP)
Python Version
3.10
Operating system
Linux
To Reproduce
We are not able to reproduce this regularly but when it happens it impacts all requests coming into a running instance of our application and never recovers. The exception happens as part of multiple queries so it does not seem to be tied to a specific query.
Error
Exception
AttributeError 'NoneType' object has no attribute '_from_objects'
Stack Trace
Additional context
We are using FastAPI to run our backend.
Beta Was this translation helpful? Give feedback.
All reactions