You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I got an issue where Pluck fields are not serializing correctly in a nested relationship.
This is an example related with my question:
I found screw_size and screw_total are serializing correctly, but test_screw_size and test_screw_total (which use Pluck) are not being included in the serialized output.
Is there a way to make Pluck work in this scenario without modifying the query?
# Model and Schema
Class Robot(Base):
__tablename__ = "robot"
__table_args__ = {"schema": "test"}
id = Column(Integer, primary_key=True)
age = Column(Integer)
size = Column(Integer)
total = Column(Integer)
...
nail = relationship("Nail", primaryjoin="Robot.part == foreign(Nail.part)")
Class Nail(Base):
__tablename__ = "nail"
__table_args__ = {"schema": "test"}
size = Column(Integer, primary_key=True)
total = Column(Integer)
...
screw = relationship("Screw", primaryjoin="Nail.id == foreign(Screw.id)")
Class Screw(Base):
__tablename__ = "screw"
__table_args__ = {"schema": "test"}
size = Column(Integer, primary_key=True)
total = Column(Integer)
...
class NailSchema(BaseSchema):
"""Schema for Nail Model"""
_model = Nail
screw_size = fields.Str(attribute="screw.size")
screw_total = fields.Str(attribute="screw.total")
# TODO: need to solve, why this is not working?
test_screw_size = fields.Pluck(ScrewSchema, "size")
test_screw_total = fields.Pluck(ScrewSchema, "total")
class ScrewSchema(BaseSchema):
"""Schema for Screw Model"""
_model = Screw
class RobotSchema(BaseSchema):
"""Schema for Robot Model"""
_model = Robot
nail_part = fields.Method("get_nail")
@staticmethod
def get_nail(obj: Robot) -> dict | None:
return NailSchema(many=True).dump(obj.nail)
I got an issue where
Pluck
fields are not serializing correctly in a nested relationship.This is an example related with my question:
I found
screw_size
andscrew_total
are serializing correctly, buttest_screw_size
andtest_screw_total
(which use Pluck) are not being included in the serialized output.Is there a way to make
Pluck
work in this scenario without modifying the query?The text was updated successfully, but these errors were encountered: