notion-py
notion-py copied to clipboard
Notion crashes when setting CollectionView filter with no id
I have a collection view that I want to set a filter on. Doing the following works just fine:
view.set('format', {
...
"property_filters": [
{
"filter": {
"filter": {
"value": {
"type": "exact",
"value": <relationid>
},
"operator": "relation_contains"
},
"property": "MRxh"
}
}
]
})
...with the one exception that the notion page itself will crash if the user tries to modify the filter in notion. The filter works, it filters as expected, but if the user tries to change it in notion, notion shows the following error:
The page stops crashing if I use an ID for the filter:
# This no longer crashes
"property_filters": [
{
"id": "d7fb...c01",
"filter": {
"filter": {
"value": {
"type": "exact",
"value": <relationid>
},
"operator": "relation_contains"
},
"property": "MRxh"
}
}
]
So apparently IDs are required when setting property filters on a view. The question is, how do I generate the ID programmatically? Or should I be setting the filter a different way?
I tried using view.build_query() to generate a filter, but that filter didn't have an ID either.
I was able to work around the problem by generating random ids using secrets.token_hex(16)
, but I don't know how stable a solution this is