MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

SaveAsync method call on BO throwing DataPortal Exception. #495

Open jayUpadhyay23 opened 6 years ago

jayUpadhyay23 commented 6 years ago

when i call asynchronous SaveAsync method on editable BO it throws below data portal exception.

Code -> RequestEdit = await RequestEdit.SaveAsync() as IRequestEdit

Exceptionn -> Exception thrown: 'Csla.DataPortalException' in mscorlib.dll Additional information: DataPortal.Update failed (RequestEdit.IsBusy == true)

If i use the synchronous method Save then i do not get any exception.

My DataPortal_Insert method does not have any asynchronous call then what may be the reason for this exception.

jonnybee commented 6 years ago

When an object has IsBusy it is typically running an Async operation. Did you check the value of IsBusy just before the code showed here?

jayUpadhyay23 commented 6 years ago

Yes i verified it. As i mentioned my DataPortal_Insert method does not have any async call. Also i debugged the code and found that all the code in DataPortal_Insert is executing correctly. Once the control goes out of this function i get this exception.

jonnybee commented 6 years ago

Do the object have async business rules?

jayUpadhyay23 commented 6 years ago

No the object does not have any business rules.

ngm011 commented 5 years ago

I don't know if this is related but I was doing some Data Portal interaction with BO's analysis lately and I'm having hard time figuring the guard against IsBusy after DP invocations.

First it looked as if after invocation DP expected for the invoked object to mark operation as idle. But it turned out that's not the case at all. Rather Save method (async variant) is the one who's in control of making an object busy and idle, which is before/after DP's interaction. So, why is DP expecting for object not to be busy?

I can see that the isbusy field is marked as non-serializable which happens to reset the field to false once it's serialized/cloned but that just looks as a side effect to me potentially masking the original problem.

rockfordlhotka commented 5 years ago

An object can be busy for several reasons. For example, if an async rule is running.

The client-side data portal SaveAsync checks to see if the object is busy before even attempting to do the save operation. In that scenario, if the object is busy, it is because of an async rule (almost certainly).

ngm011 commented 5 years ago

@rockfordlhotka I understand the basic concepts behind IsBusy.

However, what I'm pointing out here is that SaveAsync is the one marking an object as busy at the beginning of DP invocation and as idle as soon as that invocation is completed. This implies that the object is going to be busy once the DP invocation is in progress.

The only reason this doesn't seem to be a significant bug is because _isBusy field is marked as non-serializable so when the object is serialized the field is set to default value which is false. However, if you use local DP and set application context not to clone object on update, this becomes an issue i.e. DP detects that the object is busy due to save operation?!

rockfordlhotka commented 5 years ago

I see what you are saying. I keep forgetting that we allow people to save without a clone...