BO IsDirty set to false after failed save


Author
Message
Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
First of all I'd like to say that this is most likely a problem with the way the page is contructed by me. I know that because I created a small test web app that does show what I'm about to explain.



I coded this page doing testing here and there. One day I was on a record that was saved before I had set the require fields validation on the BO. I saved the record, saw the validation error message for one of the required fields being blank, and for some reason I just hit Save again. To my surprise, the form saved successfully. Or rather, the BO.Save() method return "Success". After some digging I found that the BO was losing track of the fact that the record was dirty. It was registering as dirty for the first save (IsDirty == true) but on the second save, IsDirty was false. So I think what's happening is that Strataframe isn't attempting to check rules or save. And I don't do any reloading of the record in between. The BO is part of the BasePage so it's getting stored in the Session.



I tried manually setting the record to dirty with BO.CurrentRow.SetModified() but I get an error saying that the row state has to be Unchanged in order to use SetModified or SetAdded. I tried updating a timestamp field on the BO (ex. Customer.Created = DateTime.Now) and the record was still not registering as dirty.



I'm just going to validate the required fields manually and move on, I've spent too much time on this already.



So I know there's something I'm doing wrong because it works in a simple implementation. But I wanted to get it out there and see if anyone else has had a similar experience and if they found a reason and a solution.



Thanks

Govinda
Replies
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Well, I am unsure of exactly what is happening to you, so let'st just talk about how it works which may help you out.  The IsDirty flag is a dynamic property meaing that it reflects the internal DataTable to determine if there are any modified, added, etc. records.  So the only way that this property will reflect a False is if there is nothing modified within the DataTable.

Now if an unhandled exception occurs, then you can start to have goofy behavior like this.  But the Save will always stop unless you handle the BusinessRulesChecked event and set the e.IgnoreRulesAndForceSave parm to True (The property name may be slightly differently named that what I posted...but it will be close Smile).

I would imagine that it is one of these elements that is causing this.

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Chan has a point about the transactions on his other post.  If you are using transactions, this could have an effect as well.

In any of these cases, the very first thing that I would do, is look to see if an exception is being thrown anywhere and just now showing up.  The best way to do this is to put your app in debug mode, run it, and then before you execute the code that is failing, do a Ctrl+Alt+E (default shortcut) in Visual Studio which should show the Exceptions dialog.

Check the Common Language Runtime Exceptions action:

Click OK, then go execute the code that is failing and see if any exceptions break.  This would be the first place I would start.  Remember to turn this off later otherwise you will see a lot of exceptions that are not actually causing issues and could be legtimatelly thrown and handled exceptions.

Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
I am using transactions. I'll try running through it in debug mode with that setting in the Exceptions dialog set.



Thanks guys, I'll let you know how I make out.
Chan
Chan
Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

In my case, the exception thrown caused by database FK constraint. I am able to catch it and call BusinessLayer.TransactionRollback(). However, the IsDirty doesn't return correct value.

Why don't TransactionRollback() call ResetIsSavedOnTransactionFlagOnBusinessObjects() ?



Thank you
Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
Still getting this weird behavior. Maybe I'll cook up a batch of programming funkiness. Wink



Throw in some.... I'm not handling BusinessRulesCheck so I'm not influencing a force save.



And a little... there's no exception occuring in Common Language Runtime (thrown or unhandled).



mmmmm... This might be strange too, on the second save, the BO.CurrentRow.RowState == Added. I guess I should mention here that the testing I've been doing after finding the problem has been to create a new row, skip a required field and hit save. The second save is where the problem is. So it makes sense that the row state would be Added, but based on your previous comment, Trent, the BO should detect this and set IsDirty to true. But it's not.



And an extra dash of weirdness... on the second save, when my code sees that the save result was "success", I call TransactionCommit("") (I just noticed this), and after that line, IsDirty is set to true again.



mmmm... smell that? Blink



Chan
Chan
Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

May I know if SF team is checking on it?

I need it to be solve urgently.



Please advice.

Thank you
Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
Trent,



you were right about the an exception occuring. What I had to do to see it, though, was to install the SF source code. Then I was able to see the handled exceptions, but I'm still confused about what's happening.



The first exception that's hit is in SetPropertyValue: "Object of type 'System.Int32' cannot be converted to type 'System.String'."



The line is 188:

GetPropertyInfo(OwnerType, PropertyName).SetValue(Owner, Value, Nothing)



based on the comments there, this is an issue that you've encountered before. Also, it looks like the code that would work for me has been comment out.... ?



'-- Set the property

' TLT Changed 10/14/2005 to force the value through the object type converter.

' the reason this was done was for the web. The SelectedValue of a combo box

' was a string and the actual value was an Int32. This caused a data type conversion

' error.

GetPropertyInfo(OwnerType, PropertyName).SetValue(Owner, Value, Nothing)

'With GetPropertyInfo(OwnerType, PropertyName)

' .SetValue(Owner, ConvertValue(Value, .PropertyType), Nothing)

'End With





Got any advice?



Thanks,

Govinda









Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
When faced with something like this.  The best advice that I have, especially since you are pretty confident on how to reproduce, is to post a simple sample that reproduces the behavior.  This way we can logically step through this and know that we are setting up the test the same as you.  WHen we do this, we come to resolutions much faster than going back and forth via forum posts.
Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
I was finally able to recreate the problem I was having. But before I send the whole sample, I figured I'd show this code where the last change that was made caused the problem.



The problem started when I added the rollback command after if (result != SaveUndoResult.Success). I know it doesn't make much sense to have it there because no database changes are made at that point, but I don't think it should be causing problems like this.



I'll post the sample in a few minutes



protected void btnPostBack_Click(object sender, EventArgs e)

{

try

{

BusinessLayer.TransactionBegin("", IsolationLevel.ReadCommitted);



SaveUndoResult result = MyParent.Save(true);

if (result != SaveUndoResult.Success)

{

BusinessLayer.TransactionRollback("");

}

else

{

BusinessLayer.TransactionCommit("");

}

lblMessage.Text = result.ToString();

}

catch

{



BusinessLayer.TransactionRollback("");

}

finally

{



}

}

Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
here is the sample project and data
Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
I will probably just remove that rollback command
Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
Looks like I spoke too soon. I can't just remove the command to Rollback the transaction because the second time the submit button is clicked the transaction is still active and calling the BeginTransaction command causes the following exception "A transaction with the key [DEF_TRANS_KEY] is already started".



So I tried calling Commit instead and that seems too work.



I don't think this is the greatest behavior when dealing with transactions, because I should be able to call the RollbackTransaction method where I was calling it. Are the developers looking into this? If so, do you need anything else from me?
Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
Trent,



Do you think my solution is appropriate or is this something that needs to be fixed in Strataframe?



Thank You,

Govinda
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
I am sorry I have not yet responded to this post.  I have not had a chance to look at it.   Everything came flying at me all at the same time.  We have been dealing with some server issues as well as some strange forum posts lately which has slowed down the "pipe."  We still have this on the stack to look at.  Sorry for the wait.
Govinda Berrio
Govinda Berrio
StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)StrataFrame User (324 reputation)
Group: StrataFrame Users
Posts: 94, Visits: 481
Thanks for the update.



While I'm here, I'll add that when running the sample probject, you'll see the behavior by filling only one of the fields and hitting submit twice, the first time you should see AbortedWithBrokenRules and the second time Success.



Thanks again
Chan
Chan
Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

Any update?



Thank you
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Govinda Berrio - 17 Years Ago
Govinda Berrio - 17 Years Ago
Trent L. Taylor - 17 Years Ago
Trent L. Taylor - 17 Years Ago
Govinda Berrio - 17 Years Ago
                     Hi,
In my case, the exception thrown caused by database FK...
Chan - 17 Years Ago
                         Still getting this weird behavior. Maybe I'll cook up a batch of...
Govinda Berrio - 17 Years Ago
                             Hi,
May I know if SF team is checking on it?
I need it to be...
Chan - 17 Years Ago
                                 Trent,

you were right about the an exception occuring....
Govinda Berrio - 17 Years Ago
                                     When faced with something like this. The best advice that I have,...
Trent L. Taylor - 17 Years Ago
                                         I was finally able to recreate the problem I was having. But before I...
Govinda Berrio - 17 Years Ago
                                             here is the sample project and data
Govinda Berrio - 17 Years Ago
                                                 I will probably just remove that rollback command
Govinda Berrio - 17 Years Ago
                                                     Looks like I spoke too soon. I can't just remove the command to...
Govinda Berrio - 17 Years Ago
                                                         Trent,

Do you think my solution is appropriate or is this...
Govinda Berrio - 17 Years Ago
                                                             I am sorry I have not yet responded to this post. I have not had a...
Trent L. Taylor - 17 Years Ago
                                                                 Thanks for the update.

While I'm here, I'll add that when...
Govinda Berrio - 17 Years Ago
                                                                     Hi,
Any update?

Thank you
Chan - 17 Years Ago
Chan - 17 Years Ago
Ertan Deniz - 17 Years Ago
Ertan Deniz - 17 Years Ago
Trent L. Taylor - 17 Years Ago
Andrew Harper - 10 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search