Skip to content

Commit

Permalink
Add db_session merge to list update
Browse files Browse the repository at this point in the history
  • Loading branch information
k-burt-uch committed Jan 17, 2025
1 parent 2a7e748 commit 4fe8454
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions gen3userdatalibrary/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ async def update_and_persist_list(
)
for key, value in changes_that_can_be_made:
setattr(db_list_to_update, key, value)
await self.db_session.merge(db_list_to_update)
return db_list_to_update

async def test_connection(self) -> None:
Expand Down Expand Up @@ -225,7 +226,9 @@ async def add_items_to_list(self, list_id: UUID, item_data: dict):
item_data: dict of items to add to item component of list
"""
user_list = await self.get_existing_list_or_throw(list_id)

user_list.items.update(item_data)
await self.db_session.merge(user_list)
return user_list

async def grab_all_lists_that_exist(
Expand Down
3 changes: 2 additions & 1 deletion gen3userdatalibrary/models/user_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pydantic import BaseModel, ConfigDict, Field
from sqlalchemy import UUID, Column, DateTime, Integer, String, UniqueConstraint
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.orm import declarative_base

Base = declarative_base()
Expand Down Expand Up @@ -115,7 +116,7 @@ class UserList(Base):
nullable=False,
)

items = Column(JSONB)
items = Column(MutableDict.as_mutable(JSONB))

__table_args__ = (UniqueConstraint("name", "creator", name="_name_creator_uc"),)

Expand Down

0 comments on commit 4fe8454

Please sign in to comment.