Forums » Using AMC (english) »
Transaction warnings/errors when accessing data
Added by Matthew Leingang about 7 years ago
I am writing some modules to read from a CSV file and tick some boxes in an AMC project manually. (Here "manually" still means automatically, but by programmatically setting the manual flag). I have a number of calls to the database that are generating either errors or warnings.
For instance, here is a subroutine I wrote for a package that extends AMC::DataModule::capture:
sub get_zoneid_nopage { my ($self,$sheet,$copy,$type,$id_a,$id_b,$create)=@_; # $self->begin_transaction('gZNP'); my $pages = $self->get_student_pages($sheet,$copy); # $self->end_transaction('gZNP'); my $result = undef; foreach (@$pages) { if (my $zone = $self->get_zoneid($sheet, $_->{'page'}, $copy, $type, $id_a, $id_b)) { $result = $zone; last; } } if (!$result) { warn "Page not found"; } # $self->end_transaction('gZNP'); # print "get_zoneid_nopage:result: ", $result, "\n"; return $result; }
If I leave those transaction lines commented out, I get a warning "statement request with no transaction" from the DataModule object.
If I uncomment the lines, thus surrounding with a transaction, I get a fatal error from the DBI layer, "cannot start a transaction within a transaction".
So is there a transaction or isn't there?
Interestingly, if I leave the end_transaction line in there, I get a warning "closing transaction declared as gZNP" with two spaces after "transaction". It makes me wonder if somewhere there's a $datamodule->begin_transaction
call with no argument. This might initiate a transaction called ''
(empty string), which $datamodule
would evaluate as false, but $datamodule->dbh
would allow.
I've been digging through the source for days so I thought I'd ask before continuing to figure out why this is happening.
Replies (8)
RE: Transaction warnings/errors when accessing data - Added by Matthew Leingang about 7 years ago
Grepping source, I see $self->{'_capture'}->begin_transaction;
in Zooms.pm and Manuel.pm, but I am not using any of those modules in my code.
RE: Transaction warnings/errors when accessing data - Added by Alexis Bienvenüe about 7 years ago
It makes me wonder if somewhere there's a $datamodule->begin_transaction call with no argument.
Yes, this seems to be the case.
Can you provide a minimal working code (maybe including some test SQLite databases) so that we can have a look at it and test some ideas?
RE: Transaction warnings/errors when accessing data - Added by Matthew Leingang about 7 years ago
Hi,
This isn't quite ready for prime time but I have pushed it up to github: https://github.com/nyumathclinic/AMC-Gradescope
The relevant code is in AMC/Import/Gradescope.pm
. There is some mockup data in t/mc-project
. I needed to scrub an actual AMC project of any personally identifying information to stay in compliance with US privacy laws.
If you run
$ perl Build.PL $ ./Build $ ./Build test --test_files=t/02-amc-import-gradescope.t
you should be able to see all the warnings.
RE: Transaction warnings/errors when accessing data - Added by Alexis Bienvenüe about 7 years ago
Thanks.
You call get_student_pages
somewhere. But this method asks for the module layout
to be loaded. If not loaded, it loads it (with require_module
). While loading the module layout
, the versions mechanism initiates some transactions, which interfers with yours…
Loading AMC::Basic
and calling set_debug('stderr')
(using new version hg:1919154fdd29 following your remarks) helped me to see that.
One solution is to also load the layout
module, along with the other ones, in the AMC::Import::load
method.
Maybe all that is quite misleading: maybe DataModule::require_module
should not try to load the module if not yet done, but only die with an explaination. We should think about it.
RE: Transaction warnings/errors when accessing data - Added by Matthew Leingang about 7 years ago
This is good information. But when I added
$self->{'_layout'}=$self->{'_data'}->module('layout');
to AMC::Import::load()
, there doesn't seem to be any change.
RE: Transaction warnings/errors when accessing data - Added by Alexis Bienvenüe about 7 years ago
I tested this with the development version of AMC. With the code from your git
repository, and the attached changes, the test 02-amc-import-gradescope.t
is running without warnings. I enclosed all the SQL commands in a single transaction.
transaction.diff - Changes for AMC-Gradescope (2 kB)
RE: Transaction warnings/errors when accessing data - Added by Matthew Leingang about 7 years ago
Oh, great. I will have to bite the bullet and install the development version then.
RE: Transaction warnings/errors when accessing data - Added by Alexis Bienvenüe about 7 years ago
Note that this also seems to work with version 1.2.1.
(1-8/8)