Giter Club home page Giter Club logo

Comments (5)

michaelbukachi avatar michaelbukachi commented on June 12, 2024 1

Do you mind sharing a minimum reproducible snippet?

from sqlalchemy-mixins.

federicoemartinez avatar federicoemartinez commented on June 12, 2024 1

It works in #108 with both alternatives: with declarative_base and with class Base(DeclarativeBase)

from sqlalchemy-mixins.

michaelbukachi avatar michaelbukachi commented on June 12, 2024 1

v2.0.4 should now be live

from sqlalchemy-mixins.

federicoemartinez avatar federicoemartinez commented on June 12, 2024

Sure!
This fails with
SQLAlchemy==2.0.19 and sqlalchemy-mixins==2.0.3

from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer
from sqlalchemy_mixins import AllFeaturesMixin
Base = declarative_base()

class MyOtherBaseClass(Base, AllFeaturesMixin):
    __abstract__ = True

class MyBaseClass(MyOtherBaseClass):
    __abstract__ = True

class Test(MyBaseClass):
    __tablename__ = 'test'
    id = Column(Integer(), primary_key=True)
Traceback (most recent call last):
  File "scratch_25.py", line 12, in <module>
    class Test(MyBaseClass):
  File "/venv38/lib/python3.8/site-packages/sqlalchemy/orm/decl_api.py", line 195, in __init__
    _as_declarative(reg, cls, dict_)
  File "/venv38/lib/python3.8/site-packages/sqlalchemy/orm/decl_base.py", line 247, in _as_declarative
    return _MapperConfig.setup_mapping(registry, cls, dict_, None, {})
  File "/venv38/lib/python3.8/site-packages/sqlalchemy/orm/decl_base.py", line 328, in setup_mapping
    return _ClassScanMapperConfig(
  File "/venv38/lib/python3.8/site-packages/sqlalchemy/orm/decl_base.py", line 520, in __init__
    super().__init__(registry, cls_, mapper_kw)
  File "/venv38/lib/python3.8/site-packages/sqlalchemy/orm/decl_base.py", line 344, in __init__
    instrumentation.register_class(
  File "/venv38/lib/python3.8/site-packages/sqlalchemy/orm/instrumentation.py", line 684, in register_class
    manager._update_state(
  File "/venv38/lib/python3.8/site-packages/sqlalchemy/orm/instrumentation.py", line 209, in _update_state
    registry._add_manager(self)
  File "/venv38/lib/python3.8/site-packages/sqlalchemy/orm/decl_api.py", line 1380, in _add_manager
    raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: Class '<class '__main__.Test'>' already has a primary mapper defined. 

If I edit the script to use:

from sqlalchemy.orm import DeclarativeBase

class Base(DeclarativeBase):
    pass

instead of declarative_base() it seems to work

from sqlalchemy-mixins.

michaelbukachi avatar michaelbukachi commented on June 12, 2024

@federicoemartinez Do you mind testing against #108 ?

from sqlalchemy-mixins.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.