[C#/OData] Filtering inside a component

I have…

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [ ] Bug report
  • [ ] Performance issue
  • [x] Documentation issue or request

Current behavior

I try to apply the following query to the component pagemeta:

var queryContext = QueryContext.Default.WithLanguages(CurrentLanguage);
var cmsPage = await PageClient.GetAsync(
					query: new ContentQuery { Filter = $"data/pagemeta/{CurrentLanguage}/slug/iv eq '{page}'" },
					context: queryContext,
					ct: cancellationToken);

and I get an exception:

OData operation is not supported for query: ?$filter=data/pagemeta/en/slug/iv%20eq%20’/’
meanwhile if I move the slug outside of the pagemeta component everything is fine…

Expected behavior

Being able to filter inside pagemeta component

Minimal reproduction of the problem

immagine

Environment

  • [x] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [ ] Cloud version

Version: [4.8.1]

Browser:

  • [ ] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [x] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge

What is your component definition? Which components can be added to the field?

The component definition, which is also localized:

{
    "previewUrls": {},
    "properties": {
        "validateOnPublish": false
    },
    "scripts": {},
    "isPublished": true,
    "fieldRules": [],
    "fieldsInLists": [],
    "fieldsInReferences": [],
    "fields": [
        {
            "name": "slug",
            "properties": {
                "isRequired": true,
                "isRequiredOnPublish": true,
                "isHalfWidth": false,
                "fieldType": "String",
                "editor": "Input",
                "inlineEditable": false,
                "isUnique": false,
                "minLength": 1,
                "contentType": "Unspecified"
            },
            "isLocked": false,
            "isHidden": false,
            "isDisabled": false,
            "partitioning": "invariant"
        },
        {
            "name": "title",
            "properties": {
                "isRequired": false,
                "isRequiredOnPublish": false,
                "isHalfWidth": false,
                "fieldType": "String",
                "editor": "Input",
                "inlineEditable": false,
                "isUnique": false,
                "contentType": "Unspecified"
            },
            "isLocked": false,
            "isHidden": false,
            "isDisabled": false,
            "partitioning": "invariant"
        },
        {
            "name": "description",
            "properties": {
                "isRequired": false,
                "isRequiredOnPublish": false,
                "isHalfWidth": false,
                "fieldType": "String",
                "editor": "Input",
                "inlineEditable": false,
                "isUnique": false,
                "contentType": "Unspecified"
            },
            "isLocked": false,
            "isHidden": false,
            "isDisabled": false,
            "partitioning": "invariant"
        }
    ],
    "type": "Component"
}

it’s quite simple, with only those 3 fields, no more further components down the road.

I mean the definition for the component field. Right now only fields that are part of all possible components can be used. It should be improved to allow all “conflict-free” fields.

Where I could look it up, from the front-end I have this:

You have to go to

  1. Your schema (home)
  2. Your component field
  3. Expand the component field
  4. Go to Validation tab.
  5. Check the schemas input.

it’s there:

Thats weird. I will have a look.

Btw: it should be:

Filter = $"data/pagemeta/{CurrentLanguage}/slug eq '{page}'"

Without the iv at the end.

I have tested it and have found a bug where the much better original message was replaced with the message you have seen. The problem is actually the iv at the end of the field as I said before.

Nice, as of now it does say:

Property must have a invariant language property.

but I’m wondering about which property is it about.
I tried to put [JsonConverter(typeof(InvariantConverter))](the first from Newtonsoft.Json and the second from Squidex.ClientLibrary) everywhere without much success in getting rid of that exception.

You have to note that components do not have a invariant or language fields because they cannot be localized. So your structure must be something like this.

class PageMetadata 
{
   public string Slug { get; set; }
}

class HomeData
{
   [JsonConverter(typeof(InvariantConverter))]
   public PageMetadata PageMeta { get; set; }
}

class Home : Content<HomeData>
{
}

Without InvariantConverter

To represent the json structure the HomeData would have to look like this:

class PageMetaField
{
    public PageMetadata Iv { get; set; }
}

class HomeData
{
   public PageMetaFieldPageMeta { get; set; }
}

To get rid of this, the InvariantConverter has been built.

Localized fields

If you page meta can be localized you have to define it like this:

class HomeData
{
   public Dictionary<string, PageMetadata> PageMeta { get; set; }
}

I tried as you said:


but right now there’s a new different issue:

Error converting value “/” to type ‘collAnon.com.Models.Components.PageMetadata’. Path ‘items[0].data.pagemeta.slug’, line 1, position 194.

that “/” is the current value of Slug, as if it’s trying to convert too early in path. Or it’s something more?

Are you using the X-Flatten header or so?

yes, like this:

var queryContext = QueryContext.Default.Flatten().WithLanguages(CurrentLanguage);

Then it s just

class PageMetadata 
{
   public string Slug { get; set; }
}

class HomeData
{
   public PageMetadata PageMeta { get; set; }
}

class Home : Content<HomeData>
{
}

You have to understand the JSON structure. Usually it is

{
	"data": {
		"pageMetadata": {
			"iv": {
				"slug": "..."
			}
		}
	}
}

With flatten it is just:

{
	"data": {
		"pageMetadata": {
			"slug": "..."
		}
	}
}
1 Like

It’s working :smiley:

1 Like

Nevermind, back to square 0

Squidex Request failed: {“message”:“Validation error”,“traceId”:“00-24b1396af41ff84dabc7df0552f0981c-0ec8b2917e8b6c4d-00”,“type”:“https://tools.ietf.org/html/rfc7231#section-6.5.1",“details”:["OData operation is not supported for query: ?$filter=data/pagemeta/slug%20eq%20’/’”],“statusCode”:400}

It’s like it did work for a bit, then I updated some parts of the schema from capital nomenclature to all lowercase and updated some content afterwards and here we are back again at the issue :thinking:

Hey, some things you can do:

  • If you use the latest version you should get a better message.
  • If you restart your docker instance you can ensure that it is not a caching issues.

If it does not help, check your schema names again.

ok, I did upgrade to 4.8.2 with my docker instance, the message error is still the same though, I did try to delete and recreate the schema, without success.

What I noticed though is that if I just filter by Ids(HashSet<string>) in the ContentQuery I do get the page without any issue, so given that the search and mapping went well in that case I wonder by the filter fails given that path.

I’m gonna try JsonQuery given no other choice working