Converting string to long



i’m trying to pass a HubDB table row id to a page using an URL parameter. The id fetched from request.query_dict will be a string but unfortunately hubdb_table_row() seems to accept only variables of type long.

Is there a way to convert this string into a long so hubdb_table_row() is happy?



@jolt Are you passing information from hubDB to your page or from your page to hubDB? or both? I would love it if you could dive into a little more detail about the entire process.


I’m querying a hubDB table and generating a page from the data. For each row a link will be generated in the form of:<hub db id>

In the details page I’m doing the following:

set row = request.query_dict.rowId;
set data = hubdb_table_row(<table>, row);

Pseudo code, doesn’t compile. In my example row will be a string, but hubdb_table_row only accepts numbers.


@jolt Could you parse the string for a number on the page itself? Do you have a link to your page or portal I can check it out on? You can DM the link if you would prefer.


Here is a small test case:

{% set test1 = 4999122222 %}
{% set row1 = hubdb_table_row(123, test1) %}
{% set test2 = request.query_dict.rowId %}
{% set row2 = hubdb_table_row(123, test2) %}

The last line doesn’t work. Apparently there is no way to convert a (large) number string into a number. I’ve tried to type convert the string, however using the |int filter doesn’t work (number is probably too big). You can use test2|abs to convert the string into a BigDecimal type, but again hubdb_table_row refuses that. test2|long doesn’t seem to exist…


Just to confirm that the data is as expected, could you try this and report back the output?

{% set test2 = request.query_dict.rowId %}
value is "{{ test2 }}", type is {{ type(test2) }}


Here we go:

{% set test1 = 4993770623 %}
{% set test2 = '4993770623' %}
{% set test3 = request.query_dict.get('rowId') %}

test1: value is "{{ test1 }}", type is {{ type(test1) }}<br>
test2: value is "{{ test2 }}", type is {{ type(test2) }}<br>
test3: value is "{{ test3 }}", type is {{ type(test3) }}<br>

Will result in the following output:

test1: value is "4993770623", type is long 
test2: value is "4993770623", type is str 
test3: value is "4993770623", type is str 

test1 and test2 will be accepted by hubdb_table_row(), test3 won’t.


Ok, I’ve narrowed down the problem:

{% set rowId = request.query_dict.get('rowId') %}
{% if rowId is undefined %}
{% set rowId = "1" %}
{% endif %}
{% set row = hubdb_table_row(123, rowId) %}

This works fine. The problem seems to be that once I try to publish my code, HubSpot will run the code to do syntax and validation checks. This causes hubdb_table_row() to error out, because request.query_dict.get(‘rowId’) is of course undefined in that context.

If there a way to disable this syntax check on publish?


@boulter Do you know the answer above? thanks for hopping in on this.


You’re correct that the query dict value does not exist and developers need to account for that in the preview. I’d suggest this:

{% set rowId = request.query_dict['rowId'] %}
{% if rowId %}
{% set row = hubdb_table_row(123, rowId) %} other stuff with the row...
{% endif %}


Thanks Jeff, going to at mention jolt so he gets notified.



The problem is not that the preview is incorrect, but that you’re unable to publish the code in the first place. The error message you get (“TemplateSyntaxException : Error invoking function hubdb_table_row”) isn’t helpful either. You might want to adjust that to prevent other users from having the same issue. At least this thread will help to identify a potential workaround.

Thanks a lot for your help!