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

Search does not return root page, when root is not a workpace parent level page

Open aahnik opened this issue 3 years ago • 15 comments

This is weird. I think this is a problem with Notion API and not this library. But opening this issue, so that it can be closed when this is solved.

Problem

Suppose I create a page "my page name", and add my integration to this page, then

notion.search(query="my page name")

will not give this page.

If I query for any subpage/database in this page/page within a database on this page, I will get it successfully.

Steps to reproduce

Create a new integration named "Issue32Inti".

Duplicate this page https://www.notion.so/aahnik/notion-sdk-py-540f8e2b79914654ba103c5d8a03e10e and [update]* put it inside a parent level page .share this with your integration.

Note: the page should be a subpage. Not a parent-level page. ie, it should be inside a parent page.

Now, Initialize your client object notion.

Root page

obj = notion.search(query="notion-sdk-py") # root page
Result ❌
   { 'object': 'list',
      'results': [],
      'next_cursor': None,
      'has_more': False,
    } 

Database

obj = notion.search(query="People") # database
Result ✅
{ 'object': 'list',
 'results': [{'object': 'database',
   'id': '99572135-4646-49bd-95a1-4ff08f79c7a5',
   'created_time': '2021-05-19T04:50:21.634Z',
   'last_edited_time': '2021-05-19T04:57:00.000Z',
   'title': [{'type': 'text',
     'text': {'content': 'People', 'link': None},
     'annotations': {'bold': False,
      'italic': False,
      'strikethrough': False,
      'underline': False,
      'code': False,
      'color': 'default'},
     'plain_text': 'People',
     'href': None}],
   'properties': {'Tags': {'id': 'EcDa',
     'type': 'multi_select',
     'multi_select': {'options': [{'id': '2cd67f95-2f58-4223-bc0a-de03bf87c1e2',
        'name': 'python',
        'color': 'default'},
       {'id': 'f2ae0eef-5611-4da8-97e0-9208ecec44c1',
        'name': 'expert',
        'color': 'blue'},
       {'id': '573d40b5-42bd-4035-815d-73fc4aa7d208',
        'name': 'learner',
        'color': 'purple'}]}},
    'Website': {'id': 'Z{nX', 'type': 'url', 'url': {}},
    'GitHub': {'id': '`<Mi', 'type': 'rich_text', 'rich_text': {}},
    'Name': {'id': 'title', 'type': 'title', 'title': {}}}}],
 'next_cursor': None,
 'has_more': False}

Subpage

obj = notion.search(query="Subpage 1") # subpage

Result ✅
{ 'object': 'list',
 'results': [{'object': 'page',
   'id': '4e8705d7-e6a5-4b23-853f-3b2fcc9f18fe',
   'created_time': '2021-05-19T04:45:47.349Z',
   'last_edited_time': '2021-05-19T04:49:00.000Z',
   'parent': {'type': 'page_id',
    'page_id': '540f8e2b-7991-4654-ba10-3c5d8a03e10e'},
   'archived': False,
   'properties': {'title': {'id': 'title',
     'type': 'title',
     'title': [{'type': 'text',
       'text': {'content': 'Subpage 1', 'link': None},
       'annotations': {'bold': False,
        'italic': False,
        'strikethrough': False,
        'underline': False,
        'code': False,
        'color': 'default'},
       'plain_text': 'Subpage 1',
       'href': None}]}}}],
 'next_cursor': None,
 'has_more': False}

[update] means that portion was later edited.

aahnik avatar May 19 '21 16:05 aahnik

From the doc

🚧 Search indexing is not immediate If an integration performs a search quickly after a page is shared with the integration (such as immediately after a user performs OAuth), the response may not contain the page. When an integration needs to present a user interface that depends on search results, we recommend including a Refresh button to retry the search. This will allow users to determine if the expected result is present or not, and give them a means to try again.

May be you hit that?

Blucknote avatar May 20 '21 07:05 Blucknote

Hi @Blucknote, I have waited for a sufficient amount of time, also cleared all cache, and retried several times. I could get all subpages, and everything within the page, but not the root page.

aahnik avatar May 20 '21 07:05 aahnik

Hi @Blucknote, I have waited for a sufficient amount of time, also cleared all cache, and retried several times. I could get all subpages, and everything within the page, but not the root page.

I'm tried to do a "raw" request and it seems working to me. You can see workspace parent of my page (root?). May be I'll try later with SDK

curl -X POST 'https://api.notion.com/v1/search' \      
-H 'Authorization: Bearer '"$NOTION_API_KEY"'' \      
-H 'Content-Type: application/json' \
  -H "Notion-Version: 2021-05-13" \  
        --data '{
    "query":"a page",        
    "sort":{
      "direction":"ascending",
      "timestamp":"last_edited_time"
    }
  }'
{
  "object": "list",
  "results": [
    {
      "object": "page",
      "id": "b092fabd-559f-44dc-b638-93050c3e50f6",
      "created_time": "2021-05-20T07:15:00.000Z",
      "last_edited_time": "2021-05-20T07:32:00.000Z",
      "parent": {
        "type": "workspace",
        "workspace": true
      },
      "archived": false,
      "properties": {
        "title": {
          "id": "title",
          "type": "title",
          "title": [
            {
              "type": "text",
              "text": {
                "content": "a page",
                "link": null
              },
              "annotations": {
                "bold": false,
                "italic": false,
                "strikethrough": false,
                "underline": false,
                "code": false,
                "color": "default"
              },
              "plain_text": "a page",
              "href": null
            }
          ]
        }
      }
    }
  ],
  "next_cursor": null,
  "has_more": false
}

Blucknote avatar May 20 '21 07:05 Blucknote

I'm tried to do a "raw" request and it seems working to me.

Have you followed the exact steps as described in the issue?

aahnik avatar May 20 '21 08:05 aahnik

Have you followed the exact steps as described in the issue?

Not yet. Will try to duplicate. Without that search with SDK is fine

Blucknote avatar May 20 '21 08:05 Blucknote

Have you followed the exact steps as described in the issue?

Duplicated your page and tried with SDK. Working just fine - parent workspace. My integration name differs but I'm pretty sure it's not a problem.

from pprint import pprint
pprint(
    notion.search(query="notion-sdk-py")
)
{'has_more': False,
 'next_cursor': None,
 'object': 'list',
 'results': [{'archived': False,
              'created_time': '2021-05-20T08:13:48.050Z',
              'id': 'ef3910ee-e6a3-4274-b7b6-722ab00c3265',
              'last_edited_time': '2021-05-20T08:16:00.000Z',
              'object': 'page',
              'parent': {'type': 'workspace', 'workspace': True},
              'properties': {'title': {'id': 'title',
                                       'title': [{'annotations': {'bold': False,
                                                                  'code': False,
                                                                  'color': 'default',
                                                                  'italic': False,
                                                                  'strikethrough': False,
                                                                  'underline': False},
                                                  'href': None,
                                                  'plain_text': 'notion-sdk-py',
                                                  'text': {'content': 'notion-sdk-py',
                                                           'link': None},
                                                  'type': 'text'}],
                                       'type': 'title'}}}]}

Blucknote avatar May 20 '21 08:05 Blucknote

I don't know what's wrong with my setup. I am still getting the same result, as I described in the issue. Did you try with a new integration? The integration must not have access to the parent page. Just share the "notion-sdk-py" page with the integration.

aahnik avatar May 20 '21 08:05 aahnik

I don't know what's wrong with my setup. I am still getting the same result, as I described in the issue. Did you try with a new integration? The integration must not have access to the parent page. Just share the "notion-sdk-py" page with the integration.

Me neither. Just created a new integration and shared just diplicated page and still working correctly. Also i noticed there is no way to delete integrations

image

image

Blucknote avatar May 20 '21 08:05 Blucknote

By the way did you tried with another top level (workspace parent) page? I don't think there can be problem with certain page but still

Blucknote avatar May 21 '21 08:05 Blucknote

another top-level (workspace parent) page

By the word "root", I did not mean workspace parent page. I meant the page that is shared with the integration. All the subpages are automatically shared with the integration.

The page "notion-sdk-py" was not in workspace parent in my case. It was inside a page called "Scratch". "Scratch" had many pages, but only "notion-sdk-py" was shared with integration. I could access all the subpages of "notion-sdk-py", but not itself.

Now, I share my "Home" (workspace parent level) page with the integration, and the search worked perfectly fine for "Home".

I updated my original issue description.

aahnik avatar May 23 '21 03:05 aahnik

The page "notion-sdk-py" was not in workspace parent in my case. It was inside a page called "Scratch". "Scratch" had many pages, but only "notion-sdk-py" was shared with integration. I could access all the subpages of "notion-sdk-py", but not itself.

Now when i moved "notion-sdk-py" page into not shared one I also getting empty results now. May be we should issue Notion support with this.

Blucknote avatar May 25 '21 12:05 Blucknote

Hi @makenotion and @ramnes please look at this issue.

aahnik avatar May 25 '21 13:05 aahnik

I don't think highlighting an org is of much use. You'd have more luck on Notion devs Slack server. :P

I don't see any reason the library would cause this. What if you try with curl or any other tool?

ramnes avatar May 25 '21 14:05 ramnes

@aahnik I noticed something interesting. Move page shared with integration into page which does not. On this step nothing suspecious. But When you move page on workspace level it does not shared with integration anymore

Blucknote avatar May 25 '21 14:05 Blucknote

I don't see any reason the library would cause this.

I also thought that. But I am now confused. Curl and notion-sdk-py are giving different results. That is surprising.

Curl is giving way more results. When I am doing a search,


curl -X POST 'https://api.notion.com/v1/search' \
  -H 'Authorization: Bearer '"$NOTION_API_KEY"''
	-H 'Content-Type: application/json' \
  -H "Notion-Version: 2021-05-13" \
	--data '{
    "query":"notion-sdk-py",
  }'

I am getting this (content within that page).

Using the library, I am getting nothing. (same code and result as described in issue body).

aahnik avatar May 25 '21 15:05 aahnik

Closing due to the lack of activity but if anyone still has the issue, feel free to comment and I'll reopen. :)

ramnes avatar Nov 30 '22 18:11 ramnes