jamalex / notion-py

Unofficial Python API client for Notion.so
MIT License
4.3k stars 475 forks source link

Notion crashes when setting CollectionView filter with no id #379

Open emmby opened 2 years ago

emmby commented 2 years ago

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 commented 2 years ago

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

emmby commented 2 years ago

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