-
Notifications
You must be signed in to change notification settings - Fork 872
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
Validation and hooks order #3429
Comments
Ilya, I agree :-) |
Andrey, Thank you for support:) Guys, Let me propose a testcase. @Test
public void testValidationAndHooksOrder()
{
ODatabaseDocument db = wicket.getTester().getDatabase();
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass(TEST_VALIDATION_AND_HOOKS_CLASS);
classA.createProperty("property1", OType.STRING).setNotNull(true);
classA.createProperty("property2", OType.STRING).setReadonly(true);
classA.createProperty("property3", OType.STRING).setMandatory(true);
db.registerHook(new ODocumentHookAbstract() {
@Override
public RESULT onRecordBeforeCreate(ODocument doc) {
doc.field("property1", "value1-create");
doc.field("property2", "value2-create");
doc.field("property3", "value3-create");
return RESULT.RECORD_CHANGED;
}
@Override
public RESULT onRecordBeforeUpdate(ODocument doc) {
doc.undo("property2");
if(doc.field("property3")==null) doc.field("property3", "value3-update");
return RESULT.RECORD_CHANGED;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
ODocument doc = new ODocument(classA);
//doc.field("property3", "value3-create"); //Magic line #1
doc.save();
assertEquals("value1-create", doc.field("property1"));
assertEquals("value2-create", doc.field("property2"));
assertEquals("value3-create", doc.field("property3"));
doc.field("property1", "value1-update");
doc.field("property2", "value2-update");
doc.removeField("property3");
//doc.undo("property2"); //Magic line #2
//doc.field("property3", "value3-update"); //Magic line #3
doc.save();
assertEquals("value1-update", doc.field("property1"));
assertEquals("value2-create", doc.field("property2"));
assertEquals("value3-update", doc.field("property3"));
} P.S. Btw, one more related issue: it's possible to create an document with property=null even if that property marked as "not null". Please let me know if separate issue should be created for this as well. |
I think i can add a "double" validation only in case an hook changed the record, this should fix the problem, isn't ? |
Nope your test case show that the validation block the flow before reach the hook, so you need it to be executed only after the hook call, i'm not sure how safe is to do that now, it can create problem in other cases, for example it can let some hook implemetation crash because before where protected by the validation and after this change will be not. by the way @PhantomYdn have you seen the new property "default value" this may solve your problem and this can be left as it is. anyway i think exectute the validation also after the hook is called in case the hook changed something is a good practice. i'ill implemet that. |
Lets split this question to several ones:
"default value" is not solving the whole set of problems there... |
Btw: one more idea: validation might be done like a hook. And of something should be executed before the validation - it should have approapriate order. |
@tglman This is related to your issue about validation? |
Guys, we really want to see this in 2.1. Please let me know:
|
hi @PhantomYdn for the release process i let @lvca give more details. In the design part i see the point, i was actually wondering if could have mean add a new "hook event" beforeValidate, i'm not a huge fun of hooks, and more hooks we add slower we get, but there is the use case so let's do it, feel free to implement it, and we are also happy to accept directly your own solution :) Thank you for the huge contributions you do often :) |
@PhantomYdn I've no objection on this. Moving validation as hooks would allow your special behavior. For me it's a low priority. WDYT about providing a PR about that? If all tests pass and somebody else don't see any objection we could merge it asap. |
Thanks guys! Once it will be implemented I will send a PR. |
👍 |
@PhantomYdn Any news on this PR? |
Focused on other things for a while... How many days do I have for this one to complete development? |
OrientDB 2.1 GA is scheduled for the end of the next week, but we'd need time to try this PR avoiding to put unstable things at last minute. We could also move this to 2.2. |
quite close to the final release moving to 2.2 |
Guys,
I just found out that hooks applied to a document after validation of that document.
It seems to me, that's a design gap:
Some examples for p.1:
a) Field is mandatory and readonly and no value specified on create: hook might set default one.
b) There is an autogenerated field which should not be null - hook migh generate value
What do you think?
The text was updated successfully, but these errors were encountered: