From 3b21e77076212f0dd166ab533c5a52954911efbe Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Wed, 20 Nov 2024 05:26:35 -0600 Subject: [PATCH 1/2] Update pyproject.toml --- pkgs/crouton/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/crouton/pyproject.toml b/pkgs/crouton/pyproject.toml index 435324a..5c9a5be 100644 --- a/pkgs/crouton/pyproject.toml +++ b/pkgs/crouton/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "crouton" -version = "0.0.4.dev5" +version = "0.0.4.dev6" description = "A repository to enable API CRUD Routing" authors = ["Jacob Stewart "] license = "Apache-2.0" From ba2dc08a14f186b2ec1421004b3313372b49e16e Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Wed, 20 Nov 2024 05:27:59 -0600 Subject: [PATCH 2/2] Update sqlalchemy.py --- pkgs/crouton/crouton/core/sqlalchemy.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkgs/crouton/crouton/core/sqlalchemy.py b/pkgs/crouton/crouton/core/sqlalchemy.py index 300e321..15faf5a 100644 --- a/pkgs/crouton/crouton/core/sqlalchemy.py +++ b/pkgs/crouton/crouton/core/sqlalchemy.py @@ -203,13 +203,16 @@ def route( try: db_model: Model = self._get_one()(item_id, db) - for key, value in model.dict(exclude={self._pk}).items(): + # Use exclude_unset=True to only update provided fields + update_data = model.dict(exclude={self._pk}, exclude_unset=True) + + for key, value in update_data.items(): if hasattr(db_model, key): setattr(db_model, key, value) - + db.commit() db.refresh(db_model) - + return db_model except IntegrityError as e: db.rollback()