-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
linting code containing sqlalchemy FunctionElement and compiler.compiles crashes pylint with an InferenceError exception #5679
Comments
Thank you for opening the bug. This is quite an upgrade you did there ! |
The following diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
index bb9c3de52..25837c343 100644
--- a/pylint/checkers/typecheck.py
+++ b/pylint/checkers/typecheck.py
@@ -1087,6 +1087,8 @@ accessed. Python regular expressions are accepted.",
continue
missingattr.add((owner, name))
continue
+ except astroid.InferenceError:
+ continue
# stop on the first found
break
else: However, I'd like to investigate if we can't prevent this |
I'm trying to narrow down the issue. I think I have found a solution that goes beyond catching the exception, but I wonder if my new fix isn't masking a deeper issue. @davekirby I got the reproducible example down to: from sqlalchemy.sql.expression import FunctionElement
def compile_concat_for_postgresql(compiler, **kw):
"""Implementation of compat for PostgreSQL."""
return f"compat({compiler.process(**kw)})"
class months_between(FunctionElement):
"""Amount of months between two dates represented as integer value."""
def __init__(self):
super().__init__() I don't really understand why |
Brought the reproducible example down to: from sqlalchemy.sql import roles
from test2 import FromClause
class HasMemoized(object):
...
class Generative(HasMemoized):
...
class ColumnElement(
roles.ColumnArgumentOrKeyRole,
roles.BinaryElementRole,
roles.OrderByRole,
roles.ColumnsClauseRole,
roles.LimitOffsetRole,
roles.DMLColumnRole,
roles.DDLConstraintColumnRole,
roles.StatementRole,
Generative,
):
...
class FunctionElement(ColumnElement, FromClause):
...
class months_between(FunctionElement):
"""Amount of months between two dates represented as integer value."""
def __init__(self):
super().__init__()
from operator import attrgetter
from sqlalchemy.sql import roles
class HasCacheKey(object):
...
class HasMemoized(object):
...
class MemoizedHasCacheKey(HasCacheKey, HasMemoized):
...
class ClauseElement(MemoizedHasCacheKey):
...
class ReturnsRows(roles.ReturnsRowsRole, ClauseElement):
...
class Selectable(ReturnsRows):
...
class FromClause(roles.AnonymizedFromClauseRole, Selectable):
c = property(attrgetter("columns"))
from operator import attrgetter
from sqlalchemy.sql import roles
class HasCacheKey(object):
...
class HasMemoized(object):
...
class MemoizedHasCacheKey(HasCacheKey, HasMemoized):
...
class ClauseElement(MemoizedHasCacheKey):
...
class ReturnsRows(roles.ReturnsRowsRole, ClauseElement):
...
class Selectable(ReturnsRows):
...
class FromClause(roles.AnonymizedFromClauseRole, Selectable):
c = property(attrgetter("columns")) I believe the issue is related to the imports in |
I have found a fix and submitted a PR to |
Bug description
After upgrading pylint from 2.2.2 to 2.12.2 and astroid from 2.1.0 to 2.9.3, a file that contained sqlalchemy user function definitions caused pylint to crash with an InferenceError exception. I have cut the file down to the example code below, and it still crashes. Curiously if you remove either the FunctionElement subclass OR the expression.compiles decorator it works, even though they are completely separate bits of code.
Command used
Pylint output
Expected behavior
Pylint to run to completion and report any errors in the file.
Pylint version
OS / Environment
RHEL 8
Additional dependencies
SQLAlchemy==1.4.29
The text was updated successfully, but these errors were encountered: