-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Orchard creates content item even when validation fails. #6534
Comments
Try this change, and run all the specflow tests first. Just to see if it doesn't break any unexpected feature. |
Anyone who wants to try my proposition is free to create a PR for that. And also do it for Comments if it works fine and gets sign-off. |
I would report back earlier but running all the tests after every modification is painfully slow. This is what I've attempted:
to:
The test failed because of "object moved" which has been raised before at http://stackoverflow.com/questions/23626889/orchard-cms-1-8-specflow-tests-failing-with-object-moved-302-redirection. It might've related to the AppDomain restart. I then decided to run this test manually by hooking up to IIS and SQL Server Express, installing Orchard, intentionally failing the test, old school style, just like everything described in the automated test. It behaved exactly as expected. No app restart. No redirection. Everything is just okay. The last time this SpecFlow "object moved" issue happened was after the .NET Framework version was retargetted. This time, Orchard 1.10 also had its .NET Framework version retargetted too and to confirm my speculation, I ran the same test on Orchard 1.9.2 and passed flawlessly. No complaint of "object moved" whatsoever. Therefore, the retargetting of the .NET Framework might have something to do with the failed test. However, this test passed on Orchard 1.10 before my modifications. As to how my modifications cause it to fail (regardless how remotely unrelated it might be) still eludes me. |
👍 to minimize table rows. I also agree with #6385 to have a |
@jtkech This issue is about the handling of failed validation. Even currently, Orchard is fully capable of rolling back transactions when validation fails effectively preventing unnecessary records from being inserted into database tables. The most damage it does is probably just increasing the Identity counter of the database tables |
Ok, i see, i've read too fast ;) |
I think the most damage is increasing the transaction log which can lead to the server to be down if there is no auto-growth, or if there is a hard limit on the hoster. |
I'll confess that the title only speaks the half truth. Now that I have your attention, let's try this out and reproduce the issue. Below is what happening in Orchard when validation fails:
Why bother creating the content item when the database transaction is gonna get cancelled anyway and waste precious database resources (the Identity counter of the database table
Orchard_Framework_ContentItemRecord
is increased every time a content item is created and never backs down regardless of transaction rollback)?Why not swap Step
#3
with#4
? Validate the form first and if it fails, then there's no need to even create the content item thus no transaction rollback necessary.I'll point you to the Controller's Action in question to save you the trouble,
Orchard.Core.Contents.Controllers.AdminController.CreatePOST(string, string, Action<ContentItem>)
I suggest changing the order to
By doing this, we'll be able to tell apart a content item that has been created in the database from one that has not. A new content item (including those that fail validation) has an
Id
of 0. We can use this data in ourContentPartDriver
to serve different shapes depending on whether if the content item is new or already created.Currently, the above doesn't work well since
part.ContentItem.Id
is never 0 because Orchard always creates the content item before validation occurs (the above codes run during the validation stage).The text was updated successfully, but these errors were encountered: