Umbraco-CMS icon indicating copy to clipboard operation
Umbraco-CMS copied to clipboard

ITagQuery doesn't perform as expected with multiple cultures

Open matthewcare opened this issue 1 year ago • 7 comments

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.1.0 - 13.2.0-rc.preview.33

Bug summary

I'm not 100% if this is the intended behaviour, however it was certainly very confusing to me, and definitely doesn't feel right.

Tags are not returned correctly from ITagQuery if a tag property is vary by culture. If a tag is marked as vary by culture then you must pass in a culture when using ITagQuery in order to get these tags, however then tags not marked as vary by culture are not returned.

Specifics

Content types with tag properties that are a variant won't be included in ITagQuery data unless a culture is specified, however if you specify a culture then non-variant tag properties are not included.

image

@inject ITagQuery TagQuery

....

// Only returns non-variant tags
var tags = TagQuery.GetAllContentTags();
foreach (var tag in tags)
{
    <p>@tag?.Text</p>
}

// Only returns variant tags for en-US
var enTags = TagQuery.GetAllContentTags(culture: "en-US");
foreach (var tag in enTags)
{
    <p>@tag?.Text</p>
}

// Only returns variant tags for sv
var svTags = TagQuery.GetAllContentTags(culture: "sv");
foreach (var tag in svTags)
{
    <p>@tag?.Text</p>
}

Steps to reproduce

  • Create a content type that is "Allow vary by culture".
  • Create two tag properties, and allow one of them to vary by culture
  • Implement the provided code
  • Observe that the variant tags do not show unless a culture is passed in
  • Observe that the non-variant tags do not show when a culture is passed in

Expected result / actual result

Expected: TagQuery.GetAllContentTags() should return tags that are varying by culture, as well as tags that are not varying by culture. TagQuery.GetAllContentTags(culture: "en-US") should return all tags that are not varying by culture as well as tags that are varying by culture.

Actual: TagQuery.GetAllContentTags() only returns non-varying tags TagQuery.GetAllContentTags(culture: "en-US") only return varying tags

A work around is to perform both queries, and join the results. Since this is probably what anyone that has come across this is already doing, changing the behaviour is going to be a breaking change :(

matthewcare avatar Feb 13 '24 08:02 matthewcare

Hi there @matthewcare!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

  • We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
  • If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
  • We'll replicate the issue to ensure that the problem is as described.
  • We'll decide whether the behavior is an issue or if the behavior is intended.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

github-actions[bot] avatar Feb 13 '24 08:02 github-actions[bot]

Hey! I just took a look at your issue. When you are working with multiple cultures and want to get all tags, you will need to use "*". var tags = TagQuery.GetAllContentTags(culture: "*"); Please let me know if this works

andr317c avatar Feb 16 '24 07:02 andr317c

Hi @andr317c,

The problem is getting all tags for a single culture, not all cultures. As I say, when getting tags for a single culture you must create two queries, one with no culture passed to get all tags which are not marked as a variant, and then another query with the current culture passed in to get all tags which are marked as a variant.

Passing in a wildcard will return all tags for all cultures.

To try to explain a little more.

Swedish version of the page

  • Variant tags property: En, två, tre
  • Non variant tags property (shared with both versions): 1, 2, 3

English version of the page

  • Variant tags property: One, two, three
  • Non variant tags property (shared with both versions): 1, 2, 3

If I view the Swedish version of the page TagQuery.GetAllContentTags() will only return "1, 2, 3"

TagQuery.GetAllContentTags(culture: "sv") will only return "En, två, tre"

TagQuery.GetAllContentTags(culture: "*") will return "En, två, tre, One, two, three, 1, 2, 3"

I think this is incorrect. Querying for tags with no culture specified should still return tags for the current culture, as well as the non-culture specific tags. Perhaps this is intended functionality though, and it's expected that you need to make two queries to get all of the tags for the current culture when you have both non-culture specific, and culture specific tag properties on one content type?

Thanks, Matthew

matthewcare avatar Feb 16 '24 10:02 matthewcare

Hey Matthew! Thanks a lot for clarifying. When you use TagQuery.GetAllContentTags() without specifying a culture, it defaults to null, which retrieves all invariant properties, regardless of the current culture. So if you want to retrieve all the tags, both invariant and with the Swedish culture, you'll need to execute two separate queries as you mentioned.

Please let me know if you have other questions 😄

andr317c avatar Feb 18 '24 13:02 andr317c

Hello,

I was reporting this behaviour as a bug. Not specifying a culture should return the current culture as well as invariant properties, or specifying a culture should return values for that culture (which would include invariant properties).

If I say "get me all the tags for en-GB" then I would expect it to return all tags for en-GB, not just the ones attributed to only en-GB.

Equally, when not specifying a culture, I would expect to get all tags for my current culture, not just tags which aren't attributed to a specific culture.

I understand that this is the existing behaviour, and any changes would be a breaking change and cause issues for any existing implementation, but it's definitely worth documenting somewhere (preferably in code) as this is (in my opinion) confusing behaviour.

Thanks, Matthew

matthewcare avatar Feb 19 '24 12:02 matthewcare

I agree that the document in the code is lacking, as it does not mention anything with invariant cultures if the culture is null. I will set this issue as an up for grabs. What should be fixed is the documentation in the file: src/Umbraco.Core/PublishedCache/ITagQuery.cs. The code summaries should specify that if you do not insert a culture, it gets tags with invariant culture, otherwise it will only get the specified culture, the '*' can be used to get all cultures.

andr317c avatar Feb 19 '24 12:02 andr317c

Hi @matthewcare,

We're writing to let you know that we would love some help with this issue. We feel that this issue is ideal to flag for a community member to work on it. Once flagged here, folk looking for issues to work on will know to look at yours. Of course, please feel free work on this yourself ;-). If there are any changes to this status, we'll be sure to let you know.

For more information about issues and states, have a look at this blog post.

Thanks muchly, from your friendly Umbraco GitHub bot :-)

github-actions[bot] avatar Feb 19 '24 12:02 github-actions[bot]

Hi all, I am looking in this issue and I think I am going to get my hands dirty, is this still needed to be fixed right? Thank you

ageroh avatar Mar 24 '24 08:03 ageroh