Hello,
I am trying to return a row from a data table where a simple object’s key/val pair matches a local dictionary.
The data table’s simple object looks like this:
{"municipality":["milton"],"school":["s1","s2"]}
My dictionary looks like this:
my_dict={"municipality":["milton"],"school":["s1"]}
When I run app_tables.my_table.get(object_col=my_dict)
it returns the row above, even though the values in my_dict['school']
are not equivalent to the values my_row['school']
. I would expect to get None
back since the lists do not match.
The documentation says:
# This finds all rows where object_col is a
# dict and contains a key 'the_answer' with
# the value '42' - no matter what other keys
# are in the dict.
r = app_tables.my_table.search(object_col={'the_answer': 42})
I interpret this as saying that, in order to find a match, the simple object must contain a key that equals school
(and it does), and that my_dict['school']
must equal my_row['school']
(which it does not).
The docs go on to say:
If you specify a dictionary, all specified keys must be present in the column, and all values must match the pattern specified in the dictionary.
I’m not sure what “match the pattern specified in the dictionary” refers to exactly. Based on the fact that I am able to return the row above with my_dict
, I assume that Anvil considers things to be a match based on an intersection between the two lists.
Update: I no longer think that an intersection between the two lists leads to a match. If I change my_dict['school']
to ["s1", "s2", "s3"]
the search returns None
despite the fact that the lists have common values.
Here is an app to demonstrate:
Is this the intended behaviour when searching simple objects? If so, how would I test for equality between my dictionary and a key/value pair in a simple object (I do realize I can do this in multiple steps).