I've created a carsharing app, which has car and trip classes. Both have a back populates relationship on them with the other object. I am using SQLite, and database already has a Car table with 2 entries, and trip table with 3 entries as shown in the example code.
I want to return car when a GET call is made with Car_id as input.
But getting an internal server error as below
car.trips.append(triplist)
AttributeError: 'Car' object has no attribute 'trips'
read the documentation and still not able to resolve. Appreciate any help. code.zip
I agree with @Apollo314's assessment. We are also seeing this problem in our project, and pinning sqlalchemy==1.4.35 solves the problem, as documented in #315.
Thanks a lot folks. I will try downgrading to .35 and see how that goes. M sure thats the reason, because thats the only thing that made sense so far while debugging. Appreciate the help.
Activity
Apollo314 commented on Jul 22, 2022
Probably has something to do with SQLAlchemy version. After SQLAlchemy version 1.4.35, relationships have been broken. #315
cisaacstern commented on Jul 24, 2022
I agree with @Apollo314's assessment. We are also seeing this problem in our project, and pinning sqlalchemy==1.4.35 solves the problem, as documented in #315.
syncopatedNote commented on Jul 25, 2022
Thanks a lot folks. I will try downgrading to .35 and see how that goes. M sure thats the reason, because thats the only thing that made sense so far while debugging. Appreciate the help.
Fix relationships that are broken in newer versions of sqlmodel fasta…
YuriiMotov commented on Aug 7, 2025
It was fixed by #461.
It works well in current version (SQLModel 0.0.24, SQLAlchemy 2.0.42)
Test code in the details:
DetailsBTW, you don't need to manually fetch trips and add them to car.trips