Skip to content

Commit 87b2481

Browse files
committed
fix test-cov and add extra config check
1 parent d7b0cb0 commit 87b2481

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

ninja/orm/metaclass.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ def __new__(
8080
):
8181
meta_conf = None
8282

83+
if "Config" in namespace:
84+
config_keys = {k for k, _ in getmembers(namespace["Config"])}
85+
if any(k in config_keys for k in MetaConf.model_fields.keys()):
86+
raise ConfigError(
87+
"class `Config` cannot be used to configure ModelSchema. Use `Meta` instead"
88+
)
89+
8390
if "Meta" in namespace:
8491
conf_class = namespace["Meta"]
8592
conf_dict = {

tests/test_orm_metaclass.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,29 @@ class Meta:
132132
fields = "__all__"
133133

134134
class CategorySchema5(ModelSchema):
135-
class Config:
135+
class Meta:
136136
model = Category
137137
fields = "__all__"
138138

139+
with pytest.raises(
140+
ConfigError,
141+
match=f"Field title from model {Category} already exists in the Schema",
142+
):
143+
144+
class CategorySchema6(CategorySchema5):
145+
class Meta(CategorySchema5.Meta):
146+
fields = ["title"]
147+
148+
with pytest.raises(
149+
ConfigError,
150+
match="class `Config` cannot be used to configure ModelSchema. Use `Meta` instead",
151+
):
152+
153+
class CategorySchema7(ModelSchema):
154+
class Config:
155+
model = Category
156+
fields = "__all__"
157+
139158

140159
def test_optional():
141160
class OptModel(models.Model):

0 commit comments

Comments
 (0)