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

mapper is deprecated on SQLAlchemy 1.4+ #41

Open
staticdev opened this issue Sep 14, 2021 · 1 comment · May be fixed by #44
Open

mapper is deprecated on SQLAlchemy 1.4+ #41

staticdev opened this issue Sep 14, 2021 · 1 comment · May be fixed by #44

Comments

@staticdev
Copy link

staticdev commented Sep 14, 2021

registry.map_imperatively() should be used instead.

Reference: https://docs.sqlalchemy.org/en/14/orm/mapping_api.html?highlight=mapper#sqlalchemy.orm.mapper

This involves some refactoring and updates on almost all chapters. Not sure what is the path (update the book first or the branches). I am available to help.

What needs to be done:

  1. Instead of importing MetaData on orm.py, you import his parent (registry):
from sqlalchemy.orm import registry

mapper_registry = registry()
  1. On each Table, you pass as second argument mapper_registry.metadata instead of metadata. Eg.:
order_lines = Table(
    "order_lines",
    mapper_registry.metadata,
    Column("id", Integer, primary_key=True, autoincrement=True),
    Column("sku", String(255)),
    Column("qty", Integer, nullable=False),
    Column("orderid", String(255)),
)
  1. You add the classes and tables with mapper_registry.map_imperatively instead of mapper. Eg.:
def start_mappers():
    mapper_registry.map_imperatively(model.OrderLine, order_lines)
    ...
@hjwp
Copy link
Contributor

hjwp commented Oct 8, 2021

thanks for letting me know!

That doesn't sound toooo painful as a change to implement. If you really are willing to help then I'd be very grateful -- if you fork the repository chapter and get it working in there, I can do the legwork of feeding changes thru to the rest of the chapters.

thanks very much for offering in any case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants