python - AttributeError: 'str' object has no attribute '_sa ...
stackoverflow.com › questions › 55876558Apr 27, 2019 · So you are passing a str to query the relationship attribute and creating the exact situation that the simplified example above demonstrates. The reason for the error message AttributeError: 'str' object has no attribute '_sa_instance_state', is that every ORM object has an _sa_instance_state attribute. As relationship attributes are purely for representing other ORM objects, sqlalchemy assumes that the string you have passed in is an ORM object without bothering to check first (why would it?!).