How to fill a column of type 'multi-select'? and how edit column: schema? (Solved)
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 470
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to create a telegram-bot that will create notes in notion, for this i use:
- [notion-py](https://github.com/jamalex/notion-py)
- [pyTelegramBotAPI](https://github.com/eternnoir/pyTelegramBotAPI)
then I connected my notion by adding token_v2, and then receiving data about the note that I want to save in notion, at the end i save a note on notion like this:
```
def make_notion_row():
collection_view = client.get_collection_view(list_url[temporary_category]) #take collection
print(temporary_category)
print(temporary_name)
print(temporary_link)
print(temporary_subcategory)
print(temporary_tag)
row = collection_view.collection.add_row() #make row
row.ssylka = temporary_link #this is link
row.nazvanie_zametki = temporary_name #this is name
if temporary_category == 0: #this is category, where do I want to save the note
row.stil = temporary_subcategory #this is subcategory
tags = temporary_tag.split(',') #temporary_tags is text that has many tags separated by commas. I want to get these tags as an array
for tag_one in tags:
**add_new_multi_select_value("Теги", tag_one): #"Теги" is "Tag column" in russian. in this situation, tag_one takes on the following values: ['my_hero_academia','midoria']**
else:
row.kategoria = temporary_subcategory
```
this script works, but the problem is filling in the 'Tags' column which is of type 'multi-select'.
Since in the readme 'notion-py', nothing was said about filling in the 'multi-select', therefore
I used the [bkiac](https://github.com/jamalex/notion-py/issues/51) function.
here is the slightly modified by me function:
`
art_tags = ['ryuko_matoi', 'kill_la_kill']
def add_new_multi_select_value(prop, value, style=None):
global temporary_prop_schema
if style is None:
style = choice(art_tags)
collection_schema = collection_view.collection.get(["schema"])
prop_schema = next(
(v for k, v in collection_schema.items() if v["name"] == prop), None
)
if not prop_schema:
raise ValueError(
f'"{prop}" property does not exist on the collection!'
)
if prop_schema["type"] != "multi_select":
raise ValueError(f'"{prop}" is not a multi select property!')
dupe = next(
(o for o in prop_schema["options"] if o["value"] == value), None
)
if dupe:
raise ValueError(f'"{value}" already exists in the schema!')
temporary_prop_schema = prop_schema
prop_schema["options"].append(
{"id": str(uuid1()), "value": value, "style": style}
)
collection.set("schema", collection_schema)
`
But it turned out that this function does not work, and gives the following error:
```
Traceback (most recent call last):
File "", line 1, in
add_new_multi_select_value("Теги","my_hero_academia")
File "C:\Users\laere\OneDrive\Documents\Programming\Other\notion-bot\program\notionbot\test.py", line 53, in add_new_multi_select_value
collection.set("schema", collection_schema)
File "C:\Users\laere\AppData\Local\Programs\Python\Python39-32\lib\site-packages\notion\records.py", line 115, in set
self._client.submit_transaction(
File "C:\Users\laere\AppData\Local\Programs\Python\Python39-32\lib\site-packages\notion\client.py", line 290, in submit_transaction
self.post("submitTransaction", data)
File "C:\Users\laere\AppData\Local\Programs\Python\Python39-32\lib\site-packages\notion\client.py", line 260, in post
raise HTTPError(
requests.exceptions.HTTPError: Unsaved transactions: Not allowed to edit column: schema
```
Honestly, I don’t know how to solve this problem, the question is how to fill a column of type 'multi-select'?
or how edit column: schema?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with notion/records.py, especially collection.set, and follow notion/client.py through submit_transaction and post to understand the reported schema-edit rejection. Compare collection.add_row and the multi-select helper referenced from issue #51. Done means identifying the supported multi-select update path or documenting that schema edits are unavailable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100