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
Describe the bug
the exclude argument to load_all will prevent related models from loading that are not referenced in the excluded argument.
To Reproduce
importasyncioimportuuidimportormarimportsqlalchemyfromdatabasesimportDatabaseurl="postgresql://postgres@0.0.0.0:5432/postgres"database=Database(url=url)
engine=sqlalchemy.create_engine(url)
metadata=sqlalchemy.MetaData()
classBaseMeta:
metadata=metadatadatabase=databaseclassJimmyUser(ormar.Model):
classMeta(BaseMeta):
tablename="jimmy_users"id: uuid.UUID=ormar.UUID(
primary_key=True, default=uuid.uuid4(), uuid_format="string"
)
classJimmyProfile(ormar.Model):
classMeta(BaseMeta):
tablename="jimmy_profiles"id: uuid.UUID=ormar.UUID(
primary_key=True, default=uuid.uuid4(), uuid_format="string"
)
name=ormar.String(max_length=42, default="JimmyProfile")
user: JimmyUser=ormar.ForeignKey(to=JimmyUser)
classJimmyAccount(ormar.Model):
classMeta(BaseMeta):
tablename="jimmy_accounts"id: uuid.UUID=ormar.UUID(
primary_key=True, default=uuid.uuid4(), uuid_format="string"
)
name=ormar.String(max_length=42, default="JimmyAccount")
user: JimmyUser=ormar.ForeignKey(to=JimmyUser)
asyncdefmain():
awaitdatabase.connect()
metadata.drop_all(bind=engine)
metadata.create_all(bind=engine)
user=JimmyUser()
awaituser.save()
awaitJimmyAccount(user=user).save()
awaitJimmyProfile(user=user).save()
awaituser.load_all(exclude={"jimmyprofiles"})
asserthasattr(user.jimmyaccounts[0], "name")
assertlen(user.jimmyprofiles) ==0# now flip it... and it breaks?metadata.drop_all(bind=engine)
metadata.create_all(bind=engine)
user=JimmyUser()
awaituser.save()
awaitJimmyAccount(user=user).save()
awaitJimmyProfile(user=user).save()
awaituser.load_all(exclude={"jimmyaccounts"})
assertawaitJimmyProfile.objects.get()
# so we know the profile exists, but it is not attached to the user instance, so this line throws an index error asserthasattr(user.jimmyprofiles[0], "name")
assertlen(user.jimmyaccounts) ==0if__name__=="__main__":
asyncio.run(main())
(Note: this should be a complete and concise piece of code that allows reproduction of an issue)
Expected behavior
exclude should not prevent un specified related model fields from loading
Versions (please complete the following information):
postgres
ormar version 0.11.2
The text was updated successfully, but these errors were encountered:
Describe the bug
the
exclude
argument to load_all will prevent related models from loading that are not referenced in the excluded argument.To Reproduce
(Note: this should be a complete and concise piece of code that allows reproduction of an issue)
Expected behavior
exclude should not prevent un specified related model fields from loading
Versions (please complete the following information):
ormar
version 0.11.2The text was updated successfully, but these errors were encountered: