Open sharky98 opened 2 years ago
definitely on pylint side, we run many code quality tools on sqlalchemy including flake8 with lots of extensions, mypy, pyright, pylance, black, and others.
pylint 2.15.5 reproduces the issue, while an older version I had installed, 2.11.1, does not:
$ pylint test3.py
************* Module test3
test3.py:9:0: C0304: Final newline missing (missing-final-newline)
test3.py:5:0: R0903: Too few public methods (1/2) (too-few-public-methods)
------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 5.00/10, +0.00)
I had a very similar issue in #9446 and simply removing the @classmethod
worked for me:
class UUIDAuditBase(DeclarativeBase):
"""Base db model that includes id, created_at, and update_at."""
id: Mapped[UUID] = mapped_column(primary_key=True)
created_at: Mapped[DateTime] = mapped_column(
DateTime(timezone=True),
default=functions.now(),
)
updated_at: Mapped[DateTime] = mapped_column(
DateTime(timezone=True),
default=functions.now(),
onupdate=functions.now(),
)
@declared_attr.directive
def __tablename__(cls) -> str: # noqa: N805
"""Set default table name as the lowercase version of the class name."""
return cls.__name__.lower()
Bug description
When trying to lint a file that contain the DeclarativeBase of the recent SQLAlchemy 2.0 (beta), it fails with an
astroid.exceptions.ParentMissingError: Parent not found on <Const.str l.None at 0x189844d3730>.
error. I was able to pin point the issue with the newsqlalchemy.orm.DeclarativeBase
.I understand this is most probably due to the new SQLAlchemy 2.0, but since the traceback point to pylint, I created to issue here. Maybe some guys from SQLAlchemy could help out here too? @CaselIT @zzzeek (hopefully that will ping them!)
Code that makes pylint crash
The code below is based on the migration guide and the declarative mixins. The only difference I made is to put the mixin directly in the base.
Stacktrace
Code that works
Having the mixin code not in the Base seems to resolve the issue.
So does getting rid of
DeclarativeBase
Configuration
No response
Command used
Pylint output
Expected behavior
No issues found.
Pylint version
OS / Environment
Windows 10 Poetry
Additional dependencies
sqlalchemy = {version = "^2.0.0b2", allow-prereleases = true}