Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
e-kondr01 committed Nov 2, 2023
2 parents f9e0ec5 + 0fdfa0d commit f11dbf3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions fastapi_sqlalchemy_toolkit/model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__")
)
Expand All @@ -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]}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ dependencies = [
]

[project.urls]
"Homepage" = "https://github.com/e-kondr01/fastapi-sqlalchemy-toolkit"
"Homepage" = "https://github.com/e-kondr01/fastapi-sqlalchemy-toolkit"

0 comments on commit f11dbf3

Please sign in to comment.