Open danielstandby opened 5 years ago
I just made another test. A different error appears even without using eager loading:
I just run this in shell:
from src.repository import db
from src.models.location import Location
location = Location.where('id', 5).first()
location.tags
And got this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/volume/utilities/python/lambda-layers/postgresql/python/lib/python3.7/site-packages/orator/orm/relations/wrapper.py", line 40, in __repr__
return repr(self.__wrapped__)
AttributeError: 'Collection' object has no attribute '__wrapped__'
But again, if I run the last line again after the error, it works:
>>> location.tags
<orator.orm.collection.Collection object at 0x7f11e55bcf90>
>>> list(location.tags)
[<src.models.tag.Tag object at 0x7f11e55bc190>]
>>> [tag for tag in location.tags][0].name
'test'
Hello,
First of all I'd like to tell you I really like Orator ORM, I've worked previuosly with Laravel's Eloquent :) and I like it too.
Now, I have a scenario for taggable models, very similar to the docs example.
These are the models:
src/models/tag.py
src/models/organization.py
src/models/location.py
These are the migrations:
src/migrations/2019_07_26_061519_create_organizations_table.py
src/migrations/2019_07_26_061735_create_locations_table.py
src/migrations/2019_07_26_162058_create_tags_table.py
src/migrations/2019_07_26_162121_create_taggables_table.py
After running the migrations, the database setup looks like this (I wrote down only the relevant fields):
DB connector looks like this:
src/repository/db.py
I have these records in database:
locations
table:tags
table:taggables
table:These are de dependencies in
requirements.txt
:Requirements are installed in a local folder using
-t
option and that local folder path is added to python's path so it works without issues when importing stuff.Then in shell I run:
Expected result: Location model corresponding to id 5 is assigned to variable
location
withtags
relationship already loaded.Actual result:
The curious thing is if I run the last line again after the error, it works:
Also, if the location doesn't have any references in
taggables
table, it works ok the first run.I would appreciate if you could help us find a workaround, or even better have a hotfix ASAP. We have a deadline for September 1st. And if we cannot overcome this issue soon we would be force to use a different approach. But I would really like to keep using Orator :)
Thanks.