transactions not rolled back if followed by a variable_set
greggles - January 5, 2008 - 02:53
| Project: | Pressflow Transaction |
| Version: | 5.x-1.1 |
| Component: | Documentation |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
This is an interesting bug, and I'm not sure what is causing it. I suspect it is something in variable_set (like clearing the caches) which causes this problem. Anyway, it is easy to repeat and is consistently repeatable for me:
1. Install PressFlow Transaction
2. Create a new page node that has a php input format with the following body:
<?php
// Begin transaction
$txn = new pressflow_transaction();
db_query("INSERT INTO {variable} (name, value) values ('a', 'b')");
$txn->rollback();
variable_set('something', 'value');
?>3. Preview the node
Expected results:
Run the query: select * from variable where name = 'a'; should return an empty set
Actual results:
The record is inserted and returns a value when that select is run.

#1
After discussing this in IRC, it appears that there's nothing that can be done since variable_set uses LOCK which causes an autocommit.
I suggest adding some docs like on the project page that say
"Due to the use of LOCKS in various parts of Drupal there are certain operations which will force an autocommit if they are done before a rollback. Examples include variable_set and..."
#2
I've updated documentation with the suggested warning.