# selectattr with variable value seems to have a bug

**URL:** <https://community.hubspot.com/t/selectattr-with-variable-value-seems-to-have-a-bug/70055>\
**Category:** CMS Development\
**Created:** [November 28, 2022, 10:26am UTC](https://community.hubspot.com/t/selectattr-with-variable-value-seems-to-have-a-bug/70055 "2022-11-28T10:26:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PDeT](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@PDeT](https://community.hubspot.com/u/PDeT)\
**Post date:** [November 28, 2022, 10:26am UTC](https://community.hubspot.com/t/selectattr-with-variable-value-seems-to-have-a-bug/70055/1 "2022-11-28T10:26:22Z")

</div>

Hi,

I struggling with this seemingly simple script:

{% set rows = hubdb\_table\_rows(XXXX) %}

{% set test = hubdb\_table\_row(XXXX,YYYY) %}  
{% set queryValue = test.title %}

{% set match = rows|selectattr(‘title’,‘eq’, queryValue ) %}

{{ match }}

renders: []

So I create a collection by getting the table rows.

I get a single row in the test variable, from the same table.

I take the value of one property of that row

I use that value to filter the rows and find that one row. In theory this should return at least the one row that I fetched in ‘test’, but it returns nothing.

This is not my real use case, just an illustration of what I think is a bug. In my real case I’m not setting the queryValue to a value that I fetched from the row. It is a different one and I want to find the rows that match. This is just an illustration that selectattr seems to break when the last argument is a variable.

---

<div class="post-metadata">

**Author:** ![2CUBE-Studio](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/2cube-studio/32/63871_2.png) [@2CUBE-Studio](https://community.hubspot.com/u/2CUBE-Studio)\
**Post date:** [November 28, 2022, 11:14am UTC](https://community.hubspot.com/t/selectattr-with-variable-value-seems-to-have-a-bug/70055/2 "2022-11-28T11:14:36Z")

</div>

Hi [PDeT,](https://community.hubspot.com/t5/user/viewprofilepage/user-id/286738)  
test variable stored the set of records. you need to print test variable. so you will see, that’s not a title but it’s a rows

```lia-code-sample
{# get all hubDB records at rows #}
{% set rows = hubdb_table_rows(5630042,93304468552) %}

{% set test = hubdb_table_rows(5630042,93304468553) %}
{% set queryValue = test[0].name %} {# OUTPUT Pratik #}

{# test variable get set of row. so you need to select specific row. test object stored [{},{},{}] of records. #}
{% set match = rows|selectattr('name','eq', queryValue ) %}

<pre>
 queryValue - {{ queryValue }} 
 match - {{ match }}
</pre>

```

 ![Screenshot at Nov 28 16-40-03.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/2X/e/e6d4ca45e4658af283655bd5a1feaaa56f8f5b34.jpeg)

 ![Screenshot at Nov 28 16-42-41.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/a/aaeb7888f540cfc89bebb9ee3c4e66ac13f40ea2.png)

---

<div class="post-metadata">

**Author:** ![PDeT](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@PDeT](https://community.hubspot.com/u/PDeT)\
**Post date:** [November 28, 2022, 8:14pm UTC](https://community.hubspot.com/t/selectattr-with-variable-value-seems-to-have-a-bug/70055/3 "2022-11-28T20:14:51Z")

</div>

hi @2CUBE-Studio ,

In my example, the test is filled from hubdb\_table\_row which is a different function from your example hubdb\_table\_rows.

Anyway, a lot more debugging later, it appears to be a data issue (and a hubl issue). For some records taking the title and then running a selectattr with that title returns no results, for others, it worked. So depending on the value of YYYY I had sometimes normal results and sometimes no result.

This is a bug imho, although a different one then I initially thought. If you take the value of a property of a row as the value for a filter on that same property, you should at least get the row from which it was taken as a result. An empty result is broken math 😉

Probably there happens some sanitation of some sort on the value, which then causes it not to match anymore with the original value, resulting in an empty match collection. I haven’t found the possible cause for this. At first I thought it could be the space in the string, but another record which also had a space in the title field worked fine.

I’ll go back to my client and pressure them a little harder to not try to match on titles but on id’s, which I hope will have fewer problems.

Kind regards,

Pieter
