From 1f74bdd5ff21b482d5728078984c20b2d7e1fb1e Mon Sep 17 00:00:00 2001 From: "kyle.sauder" Date: Mon, 23 Sep 2024 15:59:32 -0400 Subject: [PATCH] remove `fields` or `excludes` requirement --- ninja/orm/metaclass.py | 4 +--- tests/test_orm_metaclass.py | 10 ++-------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/ninja/orm/metaclass.py b/ninja/orm/metaclass.py index 4279bf73..f3302a32 100644 --- a/ninja/orm/metaclass.py +++ b/ninja/orm/metaclass.py @@ -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: diff --git a/tests/test_orm_metaclass.py b/tests/test_orm_metaclass.py index 2e00f58e..44396217 100644 --- a/tests/test_orm_metaclass.py +++ b/tests/test_orm_metaclass.py @@ -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"] @@ -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__"