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__"