Transactions in Wheels: question/potential bug?

8 views
Skip to first unread message

Chris Peters

unread,
Feb 10, 2012, 11:51:27 AM2/10/12
to ColdFusion on Wheels
Database: SQL Server 2008
ColdFusion: 9.0.1
Wheels: 1.1.2

In a system I'm working on, we have "service transactions" that record
services that our client performs for their customers. There is an
action in the system where you can "adjust" a service transaction.
What that does is mark the service transaction as "isAdjusted" and
creates a new record that is a copy with the adjustments applied. This
sounds complex, but there is quite a bit of callback magic that
happens to many other tables in the database when you do one of these
service transactions. (It handles equipment inventory and records tons
of other info that's used for invoicing purposes.)

In the adjust() method of the model, I start my own database
transaction, do the operations on the current and new transactions,
and commit or rollback manually based on whether validation and
callbacks run successfully on the objects. To get this working, I pass
transaction="none" to the Wheels ORM on any of its save(), update(),
create(), whatever() operations.

Here's a simplified version of the code that shows where the real
issue is.

transaction
{
// Update this record so it's marked as adjusted and undo equipment
changes
if (local.currentServiceTransaction.undo(transaction="none"))
{
if (local.newServiceTransaction.save(transaction="none"))
transaction action="commit";
else
transaction action="rollback";
}
else
{
transaction action="rollback";
}
}

The problem is with the undo() method that gets called in the first if
statement. Here's basically what it does:

<cffunction name="undo">
<cfargument name="transaction" type="string" required="false"
default="commit" hint="Whether or not to wrap this process in a
transaction.">
<cfreturn this.update(isAdjusted=1,
transaction=arguments.transaction, callbacks=false, validate=false)
and variables.
$undoClientServices(transaction=arguments.transaction)>
</cffunction>

The call to this.update() is the most important part to note.

Now look back to my first code snippet. Let's say that
local.currentServiceTransaction.undo() returns true, and it proceeds
to local.newServiceTransaction.save(). If that returns false, it's
supposed to rollback the entire transaction, but it doesn't.
isAdjusted remains true, when it should have rolled back to false.

Is this working the ways it's supposed to, or is it a bug?

Sorry if this is a little hard to follow. I can provide more details
if needed.

- Chris

Andy Bellenie

unread,
Feb 11, 2012, 4:02:25 AM2/11/12
to cfwh...@googlegroups.com
There's an internal wheels method called $invokeWithTransaction() which you can use to wrap other methods in a transaction call (it's what the main CRUD functions use). Try refactoring your code to use that and see if it fixes the problem. If so then it's something to do with your custom code. If there's still an issue it will help us locate it.


- Chris

--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.


Reply all
Reply to author
Forward
0 new messages