Taffy icon indicating copy to clipboard operation
Taffy copied to clipboard

Lucee 6 - queryToStruct is now a reserved word as it's a built in function, with different arguments

Open tomchiverton opened this issue 1 year ago • 8 comments

Probably the Taffy method should be renamed, or made available under a different name, and all the docs updated ?

Workaround, change every API resource from return representationOf( queryToStruct(... to return representationOf( this.queryToStruct(...

tomchiverton avatar Feb 22 '24 17:02 tomchiverton

Thanks for the tip, @tomchiverton! I'm happy to make whatever the appropriate changes are.

I'm surprised that queryToStruct has been added but queryToArray hasn't. If we're going to make this change, we should probably anticipate the addition of queryToArray to the language, too. It seems inevitable, and it only makes sense to keep the Taffy methods consistent with themselves.

I don't have a Lucee 6 env handy, don't have time to build one, and the version available on TryCF seems to be ~unusable at the moment.

I would prefer to not break backwards compatibility if possible. Does Lucee 6 throw an exception because of Taffy's queryToStruct method, or is there just a conflict preventing accessing the one you want to use?

I think an ideal solution would allow existing code to continue using queryToStruct while adding something else (qToStruct and qToArray?) for Lucee 6. I'd hate to break existing implementations over something so minor.

atuttle avatar Aug 13 '24 14:08 atuttle

Are you thinking Taffy could catch the exception caused by the argument mismatches? But the return rep(queryToStruct(... is inside the resource CFC so not sure how that would help - the framework can't get at the inner content ?

For CFC's that use the more modern "just return anything" it might be more possible?

tomchiverton avatar Aug 13 '24 14:08 tomchiverton

This is kind of what I was thinking:

<cffunction name="qToStruct">...</cffunction>

<cftry>
  <cffunction name="queryToStruct">
    <cfscript>
      return qToStruct(...);
    </cfscript>
  </cffunction>
  <cfcatch> <!--- fail silently ---> </cfcatch>
</cftry>

atuttle avatar Aug 13 '24 15:08 atuttle

@tomchiverton I've created a branch that I'm hoping fixes the problem. Please give it a try: https://github.com/atuttle/Taffy/tree/feat/qToStruct

It does the following:

  1. Rename the taffy-implementation of queryToStruct to qToStruct
  2. Check to see if queryToStruct is a built in function and if found, make no other changes
  3. However, if it's missing, it creates an alias for qToStruct named queryToStruct.
  4. Do the same thing for queryToArray for consistency.

see the diff here

This means that on Lucee 6, you would have the choice to use the built-in queryToStruct, or Taffy's qToStruct, and everywhere that doesn't implement queryToStruct would still have Taffy's implementation available with that name.

atuttle avatar Aug 14 '24 13:08 atuttle

@tomchiverton were you able to try out my branch?

atuttle avatar Aug 19 '24 20:08 atuttle

I might have a chance to do so today, but certainly this week.

We've migrated most of our code to use the this. workaround, as we're on Lucee 6 in production, so I think I'll need to undo that for a fair test.

tomchiverton avatar Aug 20 '24 13:08 tomchiverton

Make that next week, sorry

tomchiverton avatar Aug 23 '24 16:08 tomchiverton

This means that on Lucee 6, you would have the choice to use the built-in queryToStruct, or Taffy's qToStruct, and everywhere that doesn't implement queryToStruct would still have Taffy's implementation available with that name.

This branch doesn't seem to have any bad effects for our projects still using Lucee 5.x

All our Lucee 6.x projects have already moved to using "this.queryToStruct()" so it's kinda hard to tell the impact :)

I'd say merge the feature, then update the docs to refer to qToXxxx and note somewhere that it used to be queryToXxxx ?

tomchiverton avatar Aug 27 '24 10:08 tomchiverton

Finally released Taffy v3.7.0 today with this change.

atuttle avatar Mar 12 '25 18:03 atuttle

Hi @atuttle . For context, 3.6.0 works for me. Lucee 6.1.1.118.

With 3.7.0...

  1. The queryToArray in resource.cfc has a returntype="struct". Should be "array".

https://github.com/atuttle/Taffy/blob/9ee81b16c888e73ce34ef9c9e80ea606ff7607eb/core/resource.cfc#L84

Otherwise it throws an error: "The function [queryToArray] has an invalid return value , [Cannot cast Object type [Array] to a value of type [struct]]",

  1. I'm also experiencing a problem where only the first request is successful and any future requests just return a blank. Still trying to figure out if my code or if it's this change. Again, it all works in 3.6.0.

Thank you.

anteroortiz avatar May 22 '25 18:05 anteroortiz

Some additional findings for Issue 2. It does not like these lines at all. Even if comment out the function inside of that check, having those lines causes the second request to return a blank response.

https://github.com/atuttle/Taffy/blob/9ee81b16c888e73ce34ef9c9e80ea606ff7607eb/core/resource.cfc#L83 https://github.com/atuttle/Taffy/blob/9ee81b16c888e73ce34ef9c9e80ea606ff7607eb/core/resource.cfc#L126

anteroortiz avatar May 22 '25 19:05 anteroortiz

Ok. I did a clean install of Lucee and it seems to be working ok besides Issue 1 which is that the returntype="struct" should be "array". Thanks

anteroortiz avatar May 22 '25 20:05 anteroortiz

Final update: Issue 2 is back. I'd stick to 3.6.0 for now

anteroortiz avatar May 23 '25 15:05 anteroortiz