marshmallow-code / marshmallow-sqlalchemy

SQLAlchemy integration with marshmallow
https://marshmallow-sqlalchemy.readthedocs.io
MIT License
549 stars 94 forks source link

TypeError: SQLAlchemySchemaMeta.get_declared_fields() missing 1 required positional argument: 'dict_cls' #571

Closed AlphaJack closed 4 months ago

AlphaJack commented 4 months ago

Hi, I got the following error when launching an app that uses marshmallow-sqlalchemy:

Traceback (most recent call last):
  File "/usr/bin/superset", line 5, in <module>
    from superset.cli.main import superset
  File "/usr/lib/python3.11/site-packages/superset/__init__.py", line 21, in <module>
    from superset.app import create_app
  File "/usr/lib/python3.11/site-packages/superset/app.py", line 24, in <module>
    from superset.initialization import SupersetAppInitializer
  File "/usr/lib/python3.11/site-packages/superset/initialization/__init__.py", line 28, in <module>
    from flask_appbuilder import expose, IndexView
  File "/usr/lib/python3.11/site-packages/flask_appbuilder/__init__.py", line 5, in <module>
    from .api import ModelRestApi  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/flask_appbuilder/api/__init__.py", line 29, in <module>
    from marshmallow_sqlalchemy.fields import Related, RelatedList
  File "/usr/lib/python3.11/site-packages/marshmallow_sqlalchemy/__init__.py", line 9, in <module>
    from .schema import (
  File "/usr/lib/python3.11/site-packages/marshmallow_sqlalchemy/schema.py", line 143, in <module>
    class SQLAlchemySchema(
  File "/usr/lib/python3.11/site-packages/marshmallow/schema.py", line 116, in __new__
    klass._declared_fields = mcs.get_declared_fields(
                             ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: SQLAlchemySchemaMeta.get_declared_fields() missing 1 required positional argument: 'dict_cls'
sloria commented 4 months ago

It's likely you have incompatible versions of marshmallow and marshmallow-sqlchemy installed. The latest marshmallow-sqlalchemy release supports marshmallow>=3.10. You can run pip freeze to check which versions you have installed

AlphaJack commented 4 months ago

Hi, thank you for the quick feedback.

I have experienced this issue with the following combinations:

Marshmallow Marshmallow SQLAlchemy
3.20.0 1.0.0
3.20.0 0.30
3.20.0 0.26

EDIT

How is Marshmallow SQLAlchemy affected by SQLAlchemy?

By installing SQLAlchemy 2.0.25 instead of 1.4.44, the error becomes:

Traceback (most recent call last):
  File "/usr/bin/superset", line 5, in <module>
    from superset.cli.main import superset
  File "/usr/lib/python3.11/site-packages/superset/__init__.py", line 21, in <module>
    from superset.app import create_app
  File "/usr/lib/python3.11/site-packages/superset/app.py", line 24, in <module>
    from superset.initialization import SupersetAppInitializer
  File "/usr/lib/python3.11/site-packages/superset/initialization/__init__.py", line 35, in <module>
    from superset.extensions import (
  File "/usr/lib/python3.11/site-packages/superset/extensions/__init__.py", line 30, in <module>
    from superset.async_events.async_query_manager import AsyncQueryManager
  File "/usr/lib/python3.11/site-packages/superset/async_events/async_query_manager.py", line 26, in <module>
    from superset.utils.core import get_user_id
  File "/usr/lib/python3.11/site-packages/superset/utils/core.py", line 90, in <module>
    from superset.sql_parse import sanitize_clause
  File "/usr/lib/python3.11/site-packages/superset/sql_parse.py", line 69, in <module>
    lex = Lexer.get_default_instance()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'Lexer' has no attribute 'get_default_instance'
sloria commented 4 months ago

@AlphaJack can you try upgrading to marshmallow 3.20.2? Looks like this was fixed in 3.20.1 https://marshmallow.readthedocs.io/en/stable/changelog.html#id2

sloria commented 4 months ago

the other error you posted seems unrelated to marshmallow-sqlalchemy. see https://github.com/apache/superset/issues/24680