CMS Development

danjamescrosby
Participant

Error with SORT filter on module items forloop

I am building a custom module that has a repeater group where each item in the group is a version of our software with relevant data about it (module fields structure below for reference).

 

In the module HTML/HUBL I'm trying to sort the items in the module repeater field. Every item has a value in the sort field yet I get an error saying "Error:Invalid argument in 'sort': 3rd argument with value 'minor_version' must be a valid attribute of every item in the list".

 

This is the relevant part of the module that causes the error:

 

{% set previewReleases = [] %}{% set stableReleases = [] %}
{% for item in module.releases|sort(True, False, 'minor_version') %}
  {% if item.version_name is string_containing "-preview" or item.version_name is string_containing "-rc" or item.version_name is string_containing "-alpha" %}
    {% do previewReleases.append(item) %}
  {% else %}
    {% do stableReleases.append(item) %}
  {% endif %}
{% endfor %}

 

Does anyone know why this would be erroring?

 

Module field structure

  • Releases (Field group) - releases
    • Version name (Text) - version_name
    • Major version (Text) - major_version
    • Minor version (Text) - minor_version
    • LTS (Boolean) - lts
    • Date (Date) - date
    • Release notes (URL) - release_notes
    • Platforms (Field group) - platforms
      • Platform (Choice) - platform
        • Binary (Field group) - binary
          • URL (URL) - url
          • Platform name (Text) - platform_name

 

 

0 Upvotes
3 Replies 3
danjamescrosby
Participant

Error with SORT filter on module items forloop

I think I've identified the issue with this, I can't see why this would be expected behaviour so may be a bug.

 

To recreate the issue, create a global module as per this screenshot (both the top level and nested field groups are set as repeaters):

danjamescrosby_0-1598518376349.png

This results in the error:

danjamescrosby_1-1598518460256.png

 

It seems that having a boolean field and a nested field group causes the issue. If I change the boolean field to a choice field the error goes away. Or if I remove the second field group the error goes away.

stefen
Key Advisor | Partner
Key Advisor | Partner

Error with SORT filter on module items forloop

@danjamescrosby my first thought is that field is empty in HubDB in 1 or more rows. Have you checked that?

Stefen Phelps, Community Champion, Kelp Web Developer
0 Upvotes
danjamescrosby
Participant

Error with SORT filter on module items forloop

@stefen it's a global module with a repeater field rather than a HubDB table. And I've edited the global content for it and checked every instance in the repeater has a value for that field which it does.

 

What's a bit weird is I've created a test module with just a repeater group and the one field I want to sort by to test the functionality works and it works absolutely fine.

 

I think I'll recreate the module from scratch and see if it helps!

0 Upvotes