Skip to main content
Known Participant
February 24, 2013
Question

Weird transaction issue with implicit struct (and possible array)

  • February 24, 2013
  • 3 replies
  • 2081 views

I have the following 2 files.

mycfc.cfc

<cfcomponent  output="false">

          <cffunction name="set" output="true" returntype="void">

                    <cfargument name="text1" type="string" required="true">

                    <cfargument name="something" type="any" required="true">

                    <cfdump var="#arguments#">

          </cffunction>

</cfcomponent>

mycfc.cfm

<cfscript>

          test = {firstName="Bob in line 2"};

          i=1;

          transaction {

     new mycfc().set(Text1:"hello",something:"Bob in text");

     i++;

     new mycfc().set(Text1:"hello",something:"Bob in text again");

     new mycfc().set(Text1:"hello",something:test);

     new mycfc().set(Text1:"hello",something:{firstName="Bob in line 9"});

     test2 = {firstName="Merry"};

     writeDump(var=test2,label="line 11" );

     new mycfc().set(Text1:"hello",something:{firstName="Jenny"});

     i++;

     new mycfc().set(Text1:"hello",something:{firstName="Jenny 2"});

          }

          writeDump("i = #i#");

</cfscript>

If you run the mycfc.cfm, you will notice 4 weird things here.

1) new mycfc().set(Text1:"hello",something:test); should output "Bob in line 2", but is replace with "Bob in line 9"

2) my dump with label="line 11" is missing.

3) duplication of "Jenny 2", even you remove the writedump, you still get double "Jenny 2".

4) writeDump("i = #i#"); will give you "i = 2", which should be i = 3

This problem only happen when using transaction. It is happen to both CF9 and CF10

This topic has been closed for replies.

3 replies

Inspiring
February 28, 2013

I had a look at this, and it's a variation of a bug we (Duncan: you and I) experienced a while back, and that Brad Wood helped me lock down to a decent repro case. I blog about this current example - with links to various bugs and older blog posts - here: http://adamcameroncoldfusion.blogspot.co.uk/2013/02/another-serious-struct-literal-syntax.html

It's more serious (well: less of an edge-case, anyhow) than this example makes it look.

--

Adam

Known Participant
February 26, 2013

Thanks duncancumming.

I just found a workaround for that issue. That is if I don't use the argument name, the problem go away...

<cfscript>

          test = {firstName="Bob in line 2"};

          i = 1;

          transaction

          {

                    new mycfc().set("hello", "Bob in text");

                    i++;

                    new mycfc().set("hello", "Bob in text again");

                    new mycfc().set("hello", test);

                    new mycfc().set("hello", {firstName="Bob in line 9"});

                    test2 = {firstName="Merry"};

                    writeDump(var=test2, label="line 11");

                    new mycfc().set("hello", {firstName="Jenny"});

                    i++;

                    new mycfc().set("hello", {firstName="Jenny 2"});

          }

          writeDump("i = #i#");

</cfscript>

Participating Frequently
February 25, 2013

You shouldn't use the colon to separate argument name=value pairs.  It's undocumented, use = instead

     new mycfc().set(Text1:"hello",something:"Bob in text");

should be

     new mycfc().set(Text1 = "hello",something = "Bob in text");

Apart from that I couldn't say for the other strangeness you're experiencing.  I've seen problems using inline structures being passed as arguments, try creating them as variables and passing those instead

cfjedimaster
Inspiring
February 27, 2013

The colon _is_ documented and supported in CF10.