The hidden danger of dot (Or why should your metafield not contain . in the name)

A dot (.) – it is harmless. What harm can it do, it looks pretty innocent.

And yet it can break your Catalog UI.

Psyduck, from Pokemon Go
A dot can look pretty harmless and innocent, just like a Psyduck. Frankly, its eyes are also two dots.

Catalog UI relies on the Shell UI from CMS to render properties and such. Shell UI, in its hands, needs to know about the metadata of the properties. When you have dot in the metafield names, the MetaDataPropertyMapper will create an Property with that name on site start up. And then when you open All properties mode, Shell UI will request your content type models, and CMS Core will happily return those properties.

The problem is, Shell UI just can’t handle those (special) names. There is a specific function getPropertyMetadata(string), which treats “hello.world” as “world property of hello object”, not “a property named ‘hello.world'”. Due to nature of JavaScript – this is understandable. But that also does mean it fails to resolve “hello.world” property metadata. In the end, All Properties mode fails to load.

Everything looks normal – except the All Properties mode failed to load.

In fact, if you are using Commerce 7.6.3+, creating metafield with non alphanumberics characters is forbidden – you will get an MetaException for doing so. However, if your site was in 7.5 or earlier version, and you have one or more metafields with dot in their names – well – say goodbye to the working All Properties mode in Catalog UI when you upgrade.

You’re not out of luck, however. The solution should be renaming those “faulty” metafields to get rid of the dot. Here’s an example of replacing the dot with the underscore, a true “harmless” character:

UPDATE [dbo].[MetaField]
SET Name = Replace(Name, '.', '_') WHERE Name LIKE '%.%'

Generally, you should not manipulate your database directly. But there are cases when you need to use the power of SQL – and this is one of those. It’s always highly recommended to backup your databases before doing such task.

Now restarting the site to clear any cache, and let MetaDataPropertyMapper updates the change, and you should be good!

Leave a Reply

Your email address will not be published. Required fields are marked *