• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

StructKeyExists function has issues with recent ColdFusion 18 updates

Community Beginner ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Complex object types cannot be converted to simple values. The expression has requested a variable or an intermediate expression result as a simple value. However, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. I believe the issue is security related.

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 30, 2021 Mar 30, 2021

Thanks for that, Khalid. And I have a work-around for this, finally. 

 

First, I will get to trying things on Windows Server editions soon (again, to try to understand when this problem does and does not happen for different folks).

But until then, the work-around is that it turns out that Adobe added a new applicaiton-level property called  sameformfieldsasarray, which controls this behavior. (I really thought I'd seen news of that before, but I could not find it when searching because of course

...

Votes

Translate

Translate
Community Expert ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

I've moved this from the Using the Community forum (which is the forum for issues using the forums) to the ColdFusion forum so that proper help can be offered.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Khalid, can you offer even a simple example, so we might confirm if we see what you do (on CF2018 update 17)?

Also, are you sure NOTHING else changed in your environment? For instance, did anyone change the JVM that CF uses? If so, from what version to what version? That could be as much a cause of strange new errors, if one is not careful about how they do that.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Hello Charlie,

When submitting multiple select values, it through exception at structKeyExists function, it works fine when passing a single select option value but produce error when passing more than one value to structKeyExists funtion.

<select name="user" id="user" size="7" multiple="true">
<cfloop query="#variables.users#">
<cfoutput>
<option value="#user_id#" <cfif structKeyExists(form, "user") selected</cfif>>#variables.users.user#</option>
</cfoutput>
</cfloop>
</select>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

If that's a copy and paste you're missing a closing > after the "user")

You can also do that with

#structKeyExists(form,"user") ? 'selected' : ''#

but you probably want to do this

#structKeyExists(form,"user") AND form.user EQ user_id ? 'selected' : ''#

which is the same as

<cfif structKeyExists(form,"user") AND form.user EQ user_id>
  selected
</cfif>

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

As George has said, the following line contains an error: the closing tag > is missing.

<option value="#user_id#" <cfif structKeyExists(form, "user") selected</cfif>>#variables.users.user#

In any case, you can simplify the code by:

  • using the query directly by name (users), rather than the evaluation #variables.users#.
  • replacing cfloop with cfoutput. You would then be using 1 tag instead of 2.

An example:

<select name="user" id="user" size="7" multiple="true">
	<cfoutput query="users">
		<option value="#user_id#" <cfif structKeyExists(form, "user") and form.user eq users.user>selected</cfif>>#users.user#</option><br>
	</cfoutput>
</select>

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

This is just an example, sorry i missed the closing bracket > . In my real code there are 8 different multiple select options and those were working fine before we applied recent Coldfusion 18 patch and suddenly all of them error out at structKeyExists when we applied new patch. Our administrator revert the new patch and everything start working again.

<select name="user" id="user" size="7" multiple="true">
<cfloop query="#variables.users#">
<cfoutput>
<option value="#user_id#" <cfif structKeyExists(form, "user")> selected</cfif>>#variables.users.user#</option>
</cfoutput>
</cfloop>
</select>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

On which line does the error occur? Are you sure it's on the structKeyExists line? Please check application.log and exception.log. The error might be caused by #variables.users#.

 

In any case, as a test, you should apply Update 11 and then use

  • <cfquery name="users">
  • <cfloop query="users"> in place of <cfloop query="#variables.users#">
  • #users.user# in place of #variables.users.user#

Does the error still occur?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

BKBK_0-1616960810360.png

"#user_id#" is also a theoretical possibility. But I have assumed it is a database column name.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

Khalid,

Try this snippet and let us know:

Build - <cfoutput>#server.coldfusion.productversion#</cfoutput><br><br>
<cfset variables.users = querynew("user_id,user","Integer,Varchar",[[1,"user1"],[2,"user2"],[3,"user3"]])>
<cfif isdefined("form.submit")>
    <cfdump var="#form#"><br>
</cfif>
<cfoutput>
    <cfform name="f" action="#cgi.script_name#">
        <select name="user" id="user" size="7" multiple="true">
            <cfloop query="#variables.users#">
                <option value="#user_id#" <cfif structKeyExists(form, "user") and Listcontains(form.user,user_id)> selected</cfif>>#variables.users.user#</option>
            </cfloop>
        </select>
        <br><br>
        <input type="submit" value="Submit" name="submit">
    </cfform>
</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

The answers offered below have focused on variations of Khalid's code, but with his code (and the variants) the problem is now apparent, and it's NOT what he proposed originally: it is not a problem with structkeyexists at all (it seems to me). Instead, it's a breaking change of behavior in the March 2021 updates for cf2021, 2018, and 2016, and that is undocumented, it seems. 

 

What's changed is how CF processes form posts for fields having multiple values. Prior to the Mar updates, the form field would be available as a LIST of the multiple values, but after the updates instead they show being an ARRAY--which is unexpected, and would indeed break any apps that process fields with multiple values (like the structkeyexists Khalid was using). That's a RESULT rather than the CAUSE of the problem.

 
See below for more, but I have opened a bug report about this: https://tracker.adobe.com/#/view/CF-4211444. If you agree (or disagree) with my contention, please add your vote (and/or comment) there.
 

I have confirmed this with same code run against all 3 CF versions BEFORE last week's updates were applied and after. And FWIW, I have created a simpler form of the example Saurav offered, which demonstrates the point (see some more text to follow):

 

Build - <cfoutput>#server.coldfusion.productversion#</cfoutput><br><br>
<form name="f" action="" method="post" enctype="application/x-www-form-urlencoded">
    <select name="user" id="user" size="7" multiple="true">
        <option value="1" selected>user1</option>
        <option value="2" selected>user2</option>
        <option value="3" selected>user3</option>
    </select>
    <br><br>
    <input type="submit" value="Submit" name="submit">
</form>
<cfif isdefined("form.user")>
    <cfdump var="#form#"><br>
    <cfdump var="#isarray(form.user)#"><br>
</cfif>
 
Note I have added an isarray as well, which really asserts the point (but the content in the dump will show it). And if you may wonder why I don't use an islist also, it's because there is none. I just noticed that, and filed a feature request for it (and I acknowledge there why some would argue such is NOT needed). Please add your vote if you agree, or a comment if you do not.
 
And in case someone wonders why to bother with the actual form submission when a cfparam could set default values, the problem again is in how CF is PROCESSING the forum submission, so you can't avoid doing the form submission to demonstrate the problem.
 
And in case anyone would ask, I was doing the test against the built-in web server, so this is NOT about an issue with the web connector (or any need to update that). Indeed, I confirmed also that the problem happens EITHER with the built-in web server OR with the web connector (that was updated).

/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

@Charlie Arehart , I have ColdFusion 2021 Update 1. Your code sample runs without any error. Moreover, isarray(form.user) is False:

BKBK_0-1616959466625.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

Well, I wouldn't have reported my observation if I'd not tested it. 🙂 Here's my screnshot below. We're indeed showing the same version (update and buld number). It's indeed curious.  So now we have to wonder about other differences. FWIW, I had tested it on Windows 10 Home and on the Adobe Docker images, with the browser being either Edge (Chromium) or Firefox (latest versions of all).

 

But then curiously, I have tested on a different machine (happens to be Windows 10 Pro) and the problem does NOT happen there. I would be shocked that could make a difference. I will do more investigation, to find any other possible explanation. Again, below is my screenshot from the machine where I first identified this earlier today. Again, it fit really well as the explanation for what Khalid was saying. We still have not heard from him having tested either of the variants Saurav or I have offered. (Saurav, I have several comments on your blog post about the updates which remain unanswered.)

 

BKBK, what OS are you running, and what browser, for your testing? And Khalid? And Saurav or anyone else who may try my example code? BTW, I had meant to simplify it still more (removing the name and enctype and the select size. I wanted to make it as simple as could be. I had done that, but somehow I copy/pasted here a variant from before I'd done all that.)

 

/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2021 Mar 29, 2021

Copy link to clipboard

Copied

I have now tested with

 

Edge v89.0.x

Firefox v86.0.x

Chrome v89.0.x

 

on Windows 10 Pro. 

 

Same result as in my last post: no errors.

 

Again folks, the error that @Khalid Saleem reported ("Complex object types cannot be converted to simple values") probably has nothing to do with StructKeyExisis. The cause of the error is likely "#variables.users#" or "#variables.users.user#".

 

@Khalid Saleem , I have supplied the code with which you can prove or disprove this. Recall:

apply Update 11 and then use

  • <cfquery name="users">
  • <cfloop query="users"> in place of <cfloop query="#variables.users#">
  • #users.user# in place of #variables.users.user#

Does the error still occur?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2021 Mar 29, 2021

Copy link to clipboard

Copied

BKBK, you are confirming that it doesn't happen for you on Windows 10 pro like I did. Until you (or others here) might try it on Windows 10 home, my assertion of a bug still stands.

 

And until we hear from Khalid especially (on whether he sees the form field being an array), we can't know that what I found is not the explanation for his error (in which case your suggestion about the query aspects would not be where the problem is. Indeed, note how my example removed the query entirely. Let's hear if he runs that.) 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 29, 2021 Mar 29, 2021

Copy link to clipboard

Copied

Charlie,

I am agree with you this issue is not related with structkeyexists. After Coldfusion recent updates posted form values show in an array rather than in a list. This is the real cause of this issue. 

Build - 2018,0,11,326016

Khalid5E8D_0-1617035093230.png

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2021 Mar 29, 2021

Copy link to clipboard

Copied

Thanks for the confirmation, Khalid.

 

Now we just need to get down to how it is differing on some boxes and not others (for BKBK and even myself). So first, can you report what OS you are running your CF on?

 

(And while you report using CF2018, and BKBK reported having tested CF2021, I will say again that I had experienced the problem on all 3 recent CF versions...but differently on two boxes, depending on whether running Windows 10 Home [not working] or Pro [working], which I realize is hard to believe could be the explanation. It's all I have to go on for now. And BKBK confirmed he found it working ok after the updates with Pro as well. For the sake of consistency, I'm hoping you will confirm also that you are using Windows 10 Home, or at least something other than Windows 10 Pro.)


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

I am using Windows Server 2016 OS and ColdFusion Build 2018.0.11.326016.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

Thanks for that, Khalid. And I have a work-around for this, finally. 

 

First, I will get to trying things on Windows Server editions soon (again, to try to understand when this problem does and does not happen for different folks).

But until then, the work-around is that it turns out that Adobe added a new applicaiton-level property called  sameformfieldsasarray, which controls this behavior. (I really thought I'd seen news of that before, but I could not find it when searching because of course that name is not so obvious. It means, in effect, "render multiple form fields of the same name, or with multuple values, as an array", which is exactly our issue here).

 

And this update specifically changed that to be a default of true (see the technote for CF2018 update 11, for example, and how it points to the bug report CF-4211056, found at https://tracker.adobe.com/#/view/CF-4211056, which indicates the change). And see a comment I posted there with more, including pointing back to this.

 

I'll note here that for those who want to try the setting, it's only shown there (and in the CF docs) as something that one would set in an application.cfc, using this.sameformfieldsasarray. For those not using application.cfc, note that it can ALSO be set on the cfapplication tag instead, modifying what you may use already in your application.cfm:

 

<cfapplication name="whatever" sameformfieldsasarray="false" ... rest of your args>

 

 

Sadly, there seems no way to set this behavior ONLY for a given cfm template, if that was of interest.

 

Finally, beware NOT to just throw in a random new cfapplication tag on the cfm template with the form, in order to set this. Even if it may "work" in solving this problem, there could be other unexpected changes in behavior for your app by doing that. 

 

I still look forward to understanding the variation some of us are seeing, even after applying the updates.

 

And while the reporter of the bug above indicated that he saw different behavior based on WHETHER he was assessing the form variable within or outside of his application.cfm, in the example I offer above I was of course doing the code in its own template...and for what it's worth I had a blank application.cfm. I didn't think to mention that then, as I never fathomed it could matter. I just always put a blank application.cfm in a new folder I create with any test code, to make sure there's no impact of any application.cfm or cfc in a folder above that testing folder.)

 

Khalid, let us know if this solution works for you (whether you use application.cfc or .cfm).


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

Thanks Charlie.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Did it work for you, Khalid? If so, great. And in that case, would you want to mark my last reply as the answer for future readers who find this, to save digging through all the discussion. 🙂


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

There is an other way to fixed complex object types error. If you have few multi-select options and try to submit multiple values then this code covert the array back to list.

<cfif isDefined("form.projectCode") and isArray(form.projectCode)>
        <cfset form.projectCode = arrayToList(form.projectCode,",") />
</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Yep, if one wanted to handle things on a page by page (form by form) basis, sure that's a good tip for them to consider.

 

BTW, I will add also that I got to test this on a Server 2016 setup, and it too got the form field (with multuple values) as an array. Bottom line: it sure seems this is a "feature" of the updates from last week. Again, it was odd that BKBK and I did NOT experience the problem on Windows 10 Pro. I just really can't fathom how that plays into things.

 

Finally, thanks for marking a correct answer.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

I just ran into this issue with the "sameformfieldsasarray" setting in some of my applications after applying CF 2018 Update 11.  Isn't anyone else bothered by the fact that Adobe has changed the default value of a server-wide setting that has been in place for 20+ years?    

 

Yes, there are workarounds but something like this should not be done without warning users.  At the very least provide a setting in the Administrator to set the server-wide bahavior back to false.  I have 50 or so applications to manage and while not all of them will be impacted by this change a subset of them will be.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Yes, Michael. Agree 100%.  And this is not the only breaking change. I didn't raise a stink in this thread, as my focus had been first on finding what was the real cause of the problem, and then on sharing a work-around when I found it.

 

FWIW, I have been working on a blog post where I would be gathering up the various isssues, and yes I would have made a comment there also about how unfortunate it is that CF updates would break things. It's annoying, absolutely.

 

But Adobe folks hardly EVER chime in on these forum threads, so complaining about it here is literally "preaching to the choir". You should raise the concern on the Adobe blog post where they announced the March 2021 updates, though I will note that I have raised there several issues which have gotten no response at all. That's part of the reason I am compelled to create my own post, for whatever it's worth.

 

Finally, on the "bright side", I would point out also that it's not typical that updates introduce breaking changes (especially more than one), but it has happened. My recollection is that it happens every couple of years (so maybe once in every several updates). Can't fathom why, but again yes it should not happen at all.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation