question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not all PVCs return a correct XPath value

See original GitHub issue

In Umbraco 7 I’m using the following XPath query to fetch the ‘Not found’ error page: //error[statusCode='404'], where the statusCode property is selected from a dropdown (Umbraco.DropDown.Flexible, enable multiple choice disabled and prevalues: 404 and 500).

This XPath query doesn’t work anymore in Umbraco 8, although //error does (so it’s something with the statusCode='505' part). After checking the source of FlexibleDropdownPropertyValueConverter, it always returns System.String[] (the literal string value) as XPath value, because the intermediate value is a string[]:

https://github.com/umbraco/Umbraco-CMS/blob/3bfd9b71e290354744d677440983ecd06c5c0788/src/Umbraco.Web/PropertyEditors/ValueConverters/FlexibleDropdownPropertyValueConverter.cs#L19-L25

And the XPath value is returned from PropertyValueConverterBase by just doing a ToString() on it: https://github.com/umbraco/Umbraco-CMS/blob/3bfd9b71e290354744d677440983ecd06c5c0788/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs#L45-L46

Looking at some other Property Value Converters, these all seem to return wrong XPath values:

  • FlexibleDropdownPropertyValueConverter returns System.String[] instead of the comma seperated values
  • MediaPickerValueConverter returns Umbraco.Core.Udi[] instead of the comma seperated UDI values
  • MultiNodeTreePickerValueConverter returns Umbraco.Core.Udi[] instead of the comma seperated UDI values

Reproduction

Bug summary

UmbracoContext.Cache.GetByXPath("//error[statusCode='404']") does not return content, because the XPath value from the FlexibleDropdownPropertyValueConverter isn’t 404, but System.String[].

Specifics

Latest version: Umbraco 8.1.5

Steps to reproduce

  • Create a document type with alias error
  • Add a property statusCode using Umbraco.DropDown.Flexible, enable multiple choice disabled and prevalue: 404
  • Add content using the document type, select 404 in the dropdown, publish
  • Try to query by XPath: //error[statusCode='404']

Expected result

Return the content matched by the XPath query.

Actual result

Nothing returned, as the statusCode value doesn’t match.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
zpqrtbnkcommented, Sep 26, 2019

Methods:

  • IPropertyValueConverter.ConvertIntermediateToXPath(...) converts the “intermediate” value into an XPath value (a string or an Xml fragment, more on this later) - this is where the actual work happens.
  • IPublishedPropertyType.ConvertInterToXPath(...) uses the above method from the converter for that type to convert the “intermediate” value into the XPath value, and manages the caching of the result.
  • IPublishedProperty.GetXPathValue(...) returns the XPath value (a string or an Xml fragment) of a property - which is obtained via the above methods.

Which means that the only thing you need to bother implementing is the first one, the rest is plumbing that you should not need to bother about.

The method can return either a string, which will then be the property value in the Xml view of the cache, eg <firstName>John</firstName>. But it can also return an Xml fragment, as an XPathNavigator. The MultipleTextStringValueConverter in Core implements such a conversion, and returns something that, in the Xml view of the cache, will look like

<firstNames>
    <value>John</value>
    <value>Barbara</value>
</firstNames>
1reaction
zpqrtbnkcommented, Sep 26, 2019

Yup, valid comment about returning values or not - and then, only the elements. Glad it works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selenium Python Find Elements by XPath does not return ...
how do you know selenium does not return all elements? · 2 · Hey there, so when I run the following code, it...
Read more >
Using XPATH to examine Association values
All the DirXML-Association values are based on the DN (the Volume part ... user still has an association value it will not match...
Read more >
XPath Examples - NetIQ Identity Manager
Note that XPath 2.0 or higher is not supported by Identity Manager ... This removes the instance of <remove-all-values/> from an attribute ......
Read more >
Persistent Volumes
Because volume populators are external components, attempts to create a PVC that uses one can fail if not all the correct components are ......
Read more >
Puppeteer focus input node js. g. waitForSelector('#id', {visible
You can write a function that returns true when all images in the document ... Like this: Puppeteer is a Node. value =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found