diff --git a/fastapi_sqlalchemy_toolkit/model_manager.py b/fastapi_sqlalchemy_toolkit/model_manager.py index 744dcd3..c812f4a 100644 --- a/fastapi_sqlalchemy_toolkit/model_manager.py +++ b/fastapi_sqlalchemy_toolkit/model_manager.py @@ -846,7 +846,8 @@ async def validate_unique_constraints( for unique_constraint in self.unique_constraints: query = {} for field in unique_constraint: - query[field] = in_obj[field] + if in_obj[field] is not None: + query[field] = in_obj[field] object_exists = await self.exists( session, **query, id=FieldFilter(in_obj.get("id"), operator="__ne__") ) @@ -871,7 +872,7 @@ async def validate_unique_fields( Проверить соблюдение уникальности полей. """ for column in self.model.__table__.columns._all_columns: - if column.unique and column.name in in_obj: + if column.unique and column.name in in_obj and in_obj[column.name] is not None: if db_obj and getattr(db_obj, column.name) == in_obj[column.name]: continue attrs_to_check = {column.name: in_obj[column.name]} diff --git a/pyproject.toml b/pyproject.toml index 71d0d66..4181c6f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,4 +24,4 @@ dependencies = [ ] [project.urls] -"Homepage" = "https://github.com/e-kondr01/fastapi-sqlalchemy-toolkit" \ No newline at end of file +"Homepage" = "https://github.com/e-kondr01/fastapi-sqlalchemy-toolkit"