[Flow] Validation concept is flawed in TYPO3 Flow?
Benjamin Robichaud
b.robichaud at gmail.com
Thu Jul 17 21:10:08 CEST 2014
Just upgraded to TYPO3 Flow 2.2. I had issues in the past with validations (in the controller and on persistence) and I can see that not much has changed, safe for the @IgnoreValidation annotation that now has a flag to completely bypass the validation for an argument. I created a post previously that showed how to bypass the validation of a model when the HTTP verb was safe (GET,HEAD) using an Aspect.
Perhaps I am not using the validation correctly, but from my experience, I noticed serious issues with the whole validation stack in Flow.
First of all, let's take the example of submitting a form to create a new instance of a model. In my case, I have models with complex relationships (an Asset is associated with a Version of a Software, which is associated with a Software, which has Modules, etc.). When I submit a form to create a new instance of an Asset, the validation framework will validate ALL members of my model recursively. So it will validate my Asset fields (name, date, author, etc.) as well as the associations it has to other models, even though those models were not created by the form (Version, Software, Modules). This creates unnecessary queries to the database (to load the other models to validate) as well as wasted CPU cycles and thus the request takes more time to complete. I have partly bypassed this issue with the Aspect I mentioned earlier: I intercept the call to ActionController::initializeActionMethodValidators and remove validators for certain fields when they are annotated with @IgnoreValidation, e.g. IgnoreValidation(argumentName="software.modules")
A smart validation stack would only validate the model's members which were submitted with the form, and not the other associated models (which are only referenced by their unique identifier).
The same goes when the PersistenceManager validates all scheduled insertions/updates to the database: it will blindly validate all members of the models, regardless of the changesets that will be applied in the database. There is no need to re-validate the model all over again when only certain fields have changed.
I have created yet another Aspect that intercepts the PersistenceManager::validateObject function to resolve that issue: it eliminates the validators for all fields that are not in the changeset for a particular model.
Am I not using the validation stack correctly, or has anyone experienced similar issues?
More information about the Flow
mailing list