Skip to content

Commit

Permalink
#987 fixed error message to include data about error
Browse files Browse the repository at this point in the history
  • Loading branch information
karina-klinkeviciute committed Dec 10, 2024
1 parent a69ce65 commit 9232e05
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spinta/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,4 +1001,4 @@ class InvalidClientFileFormat(UserError):


class MissingRefModel(UserError):
template = "Property of type `ref` or `backref` should have a model in the `ref` column"
template = 'Property "{property_name}" of type "{property_type}" in the model "{model_name}" should have a model name in the `ref` column, to which it refers.'
2 changes: 1 addition & 1 deletion spinta/types/ref/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def link(context: Context, dtype: Ref) -> None:
# XXX: https://github.com/atviriduomenys/spinta/issues/44
rmodel: str = dtype.model
if rmodel is None:
raise MissingRefModel
raise MissingRefModel(model_name=dtype.prop.model.basename, property_name=dtype.prop.name, property_type=dtype.prop.dtype.name)
if rmodel == dtype.prop.model.name:
# Self reference.
dtype.model = dtype.prop.model
Expand Down
7 changes: 6 additions & 1 deletion tests/types/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ def test_raises_missing_ref_model(manifest_type, tmp_path, rc):

with pytest.raises(MissingRefModel) as e:
load_manifest(rc, manifest=manifest, manifest_type=manifest_type, tmp_path=tmp_path)
assert str(e.value) == 'Property of type `ref` or `backref` should have a model in the `ref` column\n'
assert str(e.value) == '''Property "country" of type "ref" in the model "City" should have a model name in the `ref` column, to which it refers.
Context:
model_name: City
property_name: country
property_type: ref
'''

0 comments on commit 9232e05

Please sign in to comment.