Skip to content

versioned_history example no longer works with sqlalchemy 2.0 #9220

@martell

Description

@martell

Describe the bug

The versioned_history example relies on sqlalchemy.orm.mapper which was deprecated in 1.4 and removed in 2.0.

https://docs.sqlalchemy.org/en/14/orm/mapping_api.html#sqlalchemy.orm.mapper
https://docs.sqlalchemy.org/en/20/orm/mapping_api.html#sqlalchemy.orm.mapper

With sqlalchemy 1.4 I was able to replace mapper with map_imperatively.
With sqlalchemy 2.0 the same attempted change errors out due to changes in 5ec5b0a

To reproduce

python3 -m unittest examples/versioned_history/test_versioning.py

Error

Running the example

sqlalchemy.exc.InvalidRequestError: The 'sqlalchemy.orm.mapper()' function is removed as of SQLAlchemy 2.0. 
Use the 'sqlalchemy.orm.registry.map_imperatively()` method of the ``sqlalchemy.orm.registry`` class to perform classical mapping.

Running the example with attempting to change mapper with map_imperatively

File "sqlalchemy/orm/decl_api.py", line 1357, in _add_manager
    assert manager.registry is None

Versions

  • SQLAlchemy: 2.0+

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationhigh priorityormquagmirereally hard to make the issue work "correctly" without lots of complication, riskregressionsomething worked and was broken by a change

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions