I have two ORM models I’m migrating from SqlAlchemy 1.3 and it seems like the relationship is no longer working.
class SomeSpecialType:
"""Stores a SpecialType object as an str"""
impl = types.String
python_type = SpecialType
def process_bind_param(
self, value: Optional[SpecialType], dialect: Dialect
) -> Optional[str]:
del dialect # unused
if value is not None:
return value.value
return None
process_literal_param = process_bind_param
def process_result_value(
self, value: Optional[str], dialect: Dialect
) -> SpecialType:
del dialect # unused
assert value is not None
return SpecialType(value)
BaseModel: DefaultMeta = db.Model
class SomeModel(BaseModel):
__tablename__ = 'some_table_name'
id = Column(Integer, primary_key=True)
str_column = Column(String(), nullable=False, index=True)
special_type = Column(
SomeSpecialType(),
nullable=False,
index=True,
server_default=SpecialType.SPECIAL.value,
)
other_mode = relationship(
'SomeOtherModel',
cascade='delete',
lazy='select',
uselist=False,
backref=backref('some_model', lazy='joined'),
)
class SomeOtherModel(BaseModel):
__tablename__ = 'some_other_table_name'
id = Column(Integer, primary_key=True)
some_model_id = Column(
Integer, ForeignKey('some_table_name.id'), nullable=False, unique=True
)
int_column = Column(Integer, nullable=True)
I’m trying to rewrite my queries into SqlAlchemy 2.0 style to make it future compatible. My old query is:
created_other_model = SomeOtherModel.query.first()
I’ve swapped it to
some_other_select = select(SomeOtherModel, SomeModel).join(SomeModel)
self.assertEqual(db.session.scalar(select(func.count(SomeOtherModel.id))), 1)
some_other_instance = db.session.execute(cluster_config_select).scalar_one()
However, my assert in SomeSpecialType.process_result_value
is saying the value is none which leads me to think that the columns from SomeModel are being included like they used to be with 1.3’s query
Thoughts on what I’m doing wrong with the query?