notion-py icon indicating copy to clipboard operation
notion-py copied to clipboard

Notion crashes when setting CollectionView filter with no id

Open emmby opened this issue 2 years ago • 2 comments

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:

image

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?

emmby avatar Oct 26 '22 15:10 emmby

I tried using view.build_query() to generate a filter, but that filter didn't have an ID either.

emmby avatar Oct 26 '22 15:10 emmby

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

emmby avatar Oct 26 '22 22:10 emmby