Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any validation support? #137

Open
vasib opened this issue Oct 19, 2023 · 3 comments
Open

Any validation support? #137

vasib opened this issue Oct 19, 2023 · 3 comments

Comments

@vasib
Copy link

vasib commented Oct 19, 2023

Does pyecore have any support for standard/custom validation?
I saw something about BadValueError runtime checking, but do basic EObject things like multiplicities have validation support?

@aranega
Copy link
Member

aranega commented Oct 20, 2023

Hi @vasib, thanks for the question, that raises a good point.

All depends at which level you consider the validation. Currently, the BadValueError runtime check is used to check if a model conforms well to its metamodel, at runtime. This means that if you designed a EAttribute (or EReference) to accept only a certain type (e.g: strings), and you try to put a int or another value in it, this exception will be raised. Same thing if you try to insert a value of a wrong type in a collection.

However, there is currently no out-of-the-box support for a custom validation in the sense of "validating my model regarding my domain". So, if you want to validate your model depending on some extra rules, then you need to write the validator yourself (e.g: this property on this instance of EClass should be between this value and this value, ...etc). To help, there is a bunch of functions and concepts in PyEcore that can be useful: single dispatch to go accross a full model.

In the past, I started to write something that was suppose to be generic enough to fit various validation scenarios, but at the end, I wasn't convinced by the API it provided and the way to write rules.

@vasib
Copy link
Author

vasib commented Oct 20, 2023

What do you think would be a better design?
My high level OOP skills are rubbish. What about mimicking the java implementation?

@aranega
Copy link
Member

aranega commented Oct 23, 2023

Sorry for the late answer...

That would be a solution, but it needs to be studied in detail. From memory, the early design from the gist I put in the previous message is going towards this idea, to have something that is close from the EMF implementation without being exactly this. One way to gain a little bit in fluidity would be to introduce a context parameter to the rules, and a decorator (for example) to register a rule for a dedicated metamodel and object type. The decorator could either explicitaly register the type they need to be validated against as parameter, or read the type annotation of the first parameter of the rule to do this (a little bit like the current singledispatch from the standard python library). What would be nice also, it's to have the Validator using the dispatch in itself "generated" in memory from the different rules. This must be possible using a little bit of metaprogramming. I need to find time to work on it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants