Skip to content
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

Metaclasses do not accept additional keyword arguments #1002

Closed
indietyp opened this issue Sep 23, 2021 · 1 comment
Closed

Metaclasses do not accept additional keyword arguments #1002

indietyp opened this issue Sep 23, 2021 · 1 comment
Milestone

Comments

@indietyp
Copy link

Currently, the metaclass mixins provided by flask-sqlalchemy do not accept additional keyword arguments. Due to that, it breaks compatibility to the __init_subclass_ hook.

The bug was present in SQLAlchemy, and was fixed in #5357, refer to documentation about the canonical inclusion of kwargs.

from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer

db = SQLAlchemy()


class Mixin:
    def __init_subclass__(cls, *, default=None, **kwargs):
        super().__init_subclass__(**kwargs)

        cls.default = default


class Model(db.Model, Mixin, default=2):
    id = Column(Integer, primary_key=True)

The execution of the snippet will result in:

Traceback (most recent call last):
  File "[omitted]", line 14, in <module>
    class Model(db.Model, Mixin, default=2):
TypeError: __init__() got an unexpected keyword argument 'default'

The instantiation of the class should not fail, and default should be propagated to the __init_subclass__ hook.

Environment:

  • Python version: 3.9.7
  • Flask-SQLAlchemy version: 2.5.1
  • SQLAlchemy version: 1.4.23
@davidism davidism added this to the 3.0 milestone Sep 18, 2022
@davidism
Copy link
Member

fixed in #1087

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants