Skip to content

Commit

Permalink
remove fields or excludes requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Ksauder committed Sep 23, 2024
1 parent 751a5d2 commit 1f74bdd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
4 changes: 1 addition & 3 deletions ninja/orm/metaclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ class MetaConf(BaseModel):

@model_validator(mode="after")
def check_fields(self) -> Self:
if self.model and (
(not self.exclude and not self.fields) or (self.exclude and self.fields)
):
if self.model and (self.exclude and self.fields):
raise ValueError("Specify either `exclude` or `fields`")

if self.fields_optional:
Expand Down
10 changes: 2 additions & 8 deletions tests/test_orm_metaclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ class Meta:
class CategorySchema1(ModelSchema):
class Meta:
model = Category

with pytest.raises(ValidationError, match="Specify either `exclude` or `fields`"):

class CategorySchema2(ModelSchema):
class Meta:
model = Category
exclude = ["title"]
fields = ["title"]

Expand All @@ -112,14 +106,14 @@ class Meta:
match="Use only `optional_fields`, `fields_optional` is deprecated.",
):

class CategorySchema3(ModelSchema):
class CategorySchema2(ModelSchema):
class Meta:
model = Category
fields = "__all__"
fields_optional = ["title"]
optional_fields = ["title"]

class CategorySchema4(ModelSchema):
class CategorySchema3(ModelSchema):
class Config:
model = Category
fields = "__all__"
Expand Down

0 comments on commit 1f74bdd

Please sign in to comment.