1

We have a coldfusion project on a live server, and the same project on a local development server. Both projects are nearly identical but a few components under development on the dev server. Both servers have the same coldfusion version (cf9).

Suddenly I get a "variable is undefined" error in a component on the live project. This component is exactly the same on the dev project. However the dev project does not throw this error when the exact same code is executed as on the live project.

 private void function updateRecordById(required struct properties) {
    _updateRecord(arguments.properties, aliasFrom(this.name & "_id")&" = "&
    arguments.properties.id);
}

public string function aliasFrom(required string column) {
        var matchingKey = structFindValue(variables.aliases,arguments.column,"ONE");
        return (arraylen(matchingKey)) ? matchingKey[1].key : arguments.column;
    }

The error was "Variable aliasFrom is undefined" (line nr was second line in code sample above). After simply recompiling the component on the live server (by adding writeDump("test");) and restarting the application, the error was fixed.

It looks like the live server compiled updateRecordById(), but didn't compile aliasFrom().

  • What could have caused this error?
  • How can I prevent this from happening again?
  • Why the heck don't I have this error on the dev server in exactly the same code?

more info:

This project uses coldspring to load the components once at applicationStart. The live server has 'cache template in request', 'component cache' and 'save class files' enabled. Simply restarting the application doesn't solve the problem. The component has te be recompiled.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
jan
  • 2,879
  • 2
  • 19
  • 28
  • It definitely sounds like a caching problem of some sort. Your repeated mentions of "compiling" the cfc confuse me, since CF is not usually compiled. Are you actually running `cfcompile` on the cfc or do you mean something else? – Adam Tuttle Jan 13 '12 at 13:36
  • I mean "how cf will read the component when an instance of it is created". If cf uses an older cached version, then it still shouldn't throw this error, because there was never a version of the component on that server that could throw that error. The previous version of the component never called 'aliasFrom' and didn't have the function 'aliasFrom'. – jan Jan 13 '12 at 15:59

1 Answers1

0

It is possible that ColdFusion was serving a cached version of the cfc that wasn't identical. Do you have save compiled componenets enabled on the server?

Dale Fraser
  • 4,623
  • 7
  • 39
  • 76
  • By 'save compiled components', do you mean the 'save class files' setting under caching? This is enabled on the live server and disabled on the dev server. If the live server had a cached version of the component, it wouldn't have 'aliasFrom' in it anywhere. Since 'aliasFrom' is mentioned in the error, I don't think that the server was working with a cached version. – jan Jan 13 '12 at 11:27
  • Yes thats what I meant, from my experience if it works on one and not the other something is different such as that setting. – Dale Fraser Jan 14 '12 at 01:20
  • This issue is hard to reproduce. It's probably the "save class files" that's the reason behind the different behavior between dev and live. I'll check this as the correct answer, but i'm still convinced that this isn't just a caching issue. – jan Jan 16 '12 at 10:35