schema_translate_map is ignored on refresh in MSSQL #5978
-
|
Describe the bug Schema mappings defined in This behaviour only persists when Expected behavior For the effective schema to be mapped in a refresh, similar to how other actions are mapped. To Reproduce from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session, sessionmaker
connection_string = "mssql+pyodbc://<username>:<password>@<dsnname>"
engine = create_engine(connection_string, echo="debug")
Base = declarative_base()
class Order(Base):
__tablename__ = "Order"
id = Column(Integer, primary_key=True, autoincrement=True)
Status = Column(String)
EngineSession = sessionmaker(bind=engine)
session: Session = EngineSession()
session.connection(execution_options={"schema_translate_map": {None: "1"}})
order = Order(Status="CREATED")
session.add(order)
session.commit()
""" Executes:
INSERT INTO [1].[Order] ([Status]) OUTPUT inserted.id VALUES (?)
"""
session.refresh(order)
""" Executes:
SELECT [Order].id AS [Order_id], [Order].[Status] AS [Order_Status]
FROM [Order]
WHERE [Order].id = ?
While expected:
SELECT [Order].id AS [Order_id], [Order].[Status] AS [Order_Status]
FROM [1].[Order]
WHERE [Order].id = ?
"""Versions
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
hey there - the connection is returned to the connection pool when you call commit(). to use the method that you're using, you would need to call session.connection() after each commit: instead, create an engine with the options you need: let me know if there's a document you saw that was misleading in this regard. |
Beta Was this translation helpful? Give feedback.
hey there -
the connection is returned to the connection pool when you call commit(). to use the method that you're using, you would need to call session.connection() after each commit:
instead, create an engine with the options you need: