-
-
Notifications
You must be signed in to change notification settings - Fork 94
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When I prefetch_related() a model that has JSON lists (instead of JSON dicts) I get TypeError.
To Reproduce
- Create a model with a JSON field as list such as:
class Album(ormar.Model):
ormar_config = base_ormar_config.copy(tablename="albums")
id: int = ormar.Integer(primary_key=True)
name: str = ormar.String(max_length=100, nullable=True)
shops: List[Shop] = ormar.ManyToMany(to=Shop, through=AlbumShops)
sides: list = ormar.JSON(default=list)
- Prefetch_related it
track = await Track.objects.prefetch_related(
["album__cover_pictures", "album__shops__division"]
).get(title="The Bird")
error:
@pytest.mark.asyncio
async def test_prefetch_related_with_many_to_many():
async with base_ormar_config.database:
async with base_ormar_config.database.transaction(force_rollback=True):
div = await Division.objects.create(name="Div 1")
shop1 = await Shop.objects.create(name="Shop 1", division=div)
shop2 = await Shop.objects.create(name="Shop 2", division=div)
album = Album(name="Malibu")
await album.save()
await album.shops.add(shop1)
await album.shops.add(shop2)
await Track.objects.create(album=album, title="The Bird", position=1)
await Track.objects.create(
album=album, title="Heart don't stand a chance", position=2
)
await Track.objects.create(album=album, title="The Waters", position=3)
await Cover.objects.create(title="Cover1", album=album, artist="Artist 1")
await Cover.objects.create(title="Cover2", album=album, artist="Artist 2")
> track = await Track.objects.prefetch_related(
["album__cover_pictures", "album__shops__division"]
).get(title="The Bird")
tests\test_relations\test_prefetch_related.py:381:
Expected behavior
It should support JSON dicts and lists, not just dicts
Versions (please complete the following information):
- Database backend used (mysql/sqlite/postgress)
aiosqlite - Python version
3.12 ormarversion
-0.20.1pydanticversion
pydantic==2.5.3
pydantic-extra-types==2.9.0
pydantic_core==2.14.6- if applicable
fastapiversion
fastapi==0.111.0
fastapi-cli==0.0.4
Additional context
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working