0

I have the following code:

markers = db.relationship("Marker", back_populates="track")


    @hybrid_property
    def first_marker(self):
        if (len(self.markers) > 0) is True:
            return self.markers[0]
        return None

and using marshmallow to serialize it. But when I run the app, it raises an error:

TypeError: object of type 'InstrumentedAttribute' has no len()

What I want is this hybrid property to return the first element of the markers list. It looks like when I start the app, marshmallow is calling this function with self.markers as the "Relationship" object, but why? How could I fix this?

Thank you for your help!

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
3xecutor
  • 101
  • 2
  • 8
  • It'll help if you can narrow down the code to a [smaller example](http://sscce.org/), showing the marshmallow schema and the exception traceback. – askaroni Sep 23 '19 at 06:04
  • I found the issue. My marshmallow Schema was: fields = ( Track.first_marker.key, ) but it should have been fields = ( "first_marker", ) Thank you for your help. – 3xecutor Sep 23 '19 at 14:38

0 Answers0