Commit 6befd8c
committed
Fix AttributeError when using Nuitka-compiled models
When using tortoise-orm with Nuitka-compiled Python code, the _get_comments
function fails with an AttributeError because inspect.getsourcefile() returns
None for compiled modules, and the code attempts to call .endswith() on None.
This error occurs in the following stack trace:
- _get_comments() calls inspect.getsource(cls)
- inspect.getsource() -> inspect.getsourcelines() -> inspect.findsource()
- inspect.findsourcefile() returns None for Nuitka-compiled modules
- inspect.findsource() tries to call filename.endswith(), causing AttributeError
The fix adds AttributeError to the exception handling in _get_comments(),
allowing the function to gracefully return an empty dict when source code
cannot be retrieved from compiled modules.
Fixes: AttributeError: 'NoneType' object has no attribute 'endswith'1 parent 1d2400b commit 6befd8c
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
0 commit comments