better-notion 2.1.0__py3-none-any.whl → 2.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- better_notion/utils/agents/schemas.py +10 -2
- better_notion/utils/agents/workspace.py +158 -23
- {better_notion-2.1.0.dist-info → better_notion-2.1.2.dist-info}/METADATA +1 -1
- {better_notion-2.1.0.dist-info → better_notion-2.1.2.dist-info}/RECORD +7 -7
- {better_notion-2.1.0.dist-info → better_notion-2.1.2.dist-info}/WHEEL +0 -0
- {better_notion-2.1.0.dist-info → better_notion-2.1.2.dist-info}/entry_points.txt +0 -0
- {better_notion-2.1.0.dist-info → better_notion-2.1.2.dist-info}/licenses/LICENSE +0 -0
|
@@ -458,8 +458,10 @@ class TaskSchema:
|
|
|
458
458
|
SelectOption.option("Low", "blue"),
|
|
459
459
|
],
|
|
460
460
|
),
|
|
461
|
-
#
|
|
462
|
-
|
|
461
|
+
# Dependencies: Self-referential relation (will be updated after database creation)
|
|
462
|
+
"Dependencies": PropertyBuilder.relation("Dependencies", dual_property=False),
|
|
463
|
+
# Related Work Issue: Relation to Work Issues (will be updated after database creation)
|
|
464
|
+
"Related Work Issue": PropertyBuilder.relation("Related Work Issue", dual_property=False),
|
|
463
465
|
"Estimated Hours": PropertyBuilder.number("Estimated Hours"),
|
|
464
466
|
"Actual Hours": PropertyBuilder.number("Actual Hours"),
|
|
465
467
|
"Assignee": PropertyBuilder.people("Assignee"),
|
|
@@ -557,6 +559,10 @@ class WorkIssueSchema:
|
|
|
557
559
|
"Proposed Solution": PropertyBuilder.text("Proposed Solution"),
|
|
558
560
|
"Related Idea": PropertyBuilder.relation("Related Idea", dual_property=False),
|
|
559
561
|
"Fix Tasks": PropertyBuilder.relation("Fix Tasks", dual_property=False),
|
|
562
|
+
# Blocking Tasks: Tasks blocked by this work issue (will be updated after database creation)
|
|
563
|
+
"Blocking Tasks": PropertyBuilder.relation("Blocking Tasks", dual_property=False),
|
|
564
|
+
# Caused Incidents: Incidents caused by this work issue (will be updated after database creation)
|
|
565
|
+
"Caused Incidents": PropertyBuilder.relation("Caused Incidents", dual_property=False),
|
|
560
566
|
}
|
|
561
567
|
|
|
562
568
|
|
|
@@ -599,6 +605,8 @@ class IncidentSchema:
|
|
|
599
605
|
],
|
|
600
606
|
),
|
|
601
607
|
"Fix Task": PropertyBuilder.relation("Fix Task", dual_property=False),
|
|
608
|
+
# Root Cause Work Issue: Relation to Work Issues (will be updated after database creation)
|
|
609
|
+
"Root Cause Work Issue": PropertyBuilder.relation("Root Cause Work Issue", dual_property=False),
|
|
602
610
|
"Root Cause": PropertyBuilder.text("Root Cause"),
|
|
603
611
|
"Detected Date": PropertyBuilder.date("Detected Date"),
|
|
604
612
|
"Resolved Date": PropertyBuilder.date("Resolved Date"),
|
|
@@ -93,10 +93,17 @@ class WorkspaceInitializer:
|
|
|
93
93
|
logger.error(error_msg)
|
|
94
94
|
raise Exception(error_msg) from e
|
|
95
95
|
|
|
96
|
-
# Check for existing workspace
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
# Check for existing workspace
|
|
97
|
+
existing = await WorkspaceMetadata.detect_workspace(parent, self._client)
|
|
98
|
+
|
|
99
|
+
if existing:
|
|
100
|
+
if skip_detection:
|
|
101
|
+
# --reset flag: Delete all existing databases first
|
|
102
|
+
logger.warning(f"Reset mode: Deleting {len(existing.get('database_ids', {}))} existing databases...")
|
|
103
|
+
await self._delete_existing_databases(parent, existing.get("database_ids", {}))
|
|
104
|
+
logger.info("All existing databases deleted")
|
|
105
|
+
else:
|
|
106
|
+
# Normal mode: Raise error if workspace exists
|
|
100
107
|
workspace_info = {
|
|
101
108
|
"workspace_id": existing.get("workspace_id", "unknown"),
|
|
102
109
|
"workspace_name": existing.get("workspace_name", workspace_name),
|
|
@@ -126,20 +133,31 @@ class WorkspaceInitializer:
|
|
|
126
133
|
("Incidents", "incidents", self._create_incidents_db),
|
|
127
134
|
]
|
|
128
135
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
f"
|
|
138
|
-
f"
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
136
|
+
try:
|
|
137
|
+
for display_name, key, create_func in databases_order:
|
|
138
|
+
try:
|
|
139
|
+
logger.info(f"Creating {display_name} database...")
|
|
140
|
+
await create_func(parent)
|
|
141
|
+
logger.info(f"✓ {display_name} database created: {self._database_ids[key]}")
|
|
142
|
+
except Exception as e:
|
|
143
|
+
# Clean up databases created so far
|
|
144
|
+
logger.error(f"Failed to create {display_name} database: {str(e)}")
|
|
145
|
+
logger.warning(f"Cleaning up {len(self._database_ids)} databases that were created...")
|
|
146
|
+
await self._delete_existing_databases(parent, self._database_ids)
|
|
147
|
+
error_msg = (
|
|
148
|
+
f"Failed to create {display_name} database: {str(e)}\n"
|
|
149
|
+
f"All partially created databases have been deleted.\n"
|
|
150
|
+
f"Parent page: {parent_page_id}\n"
|
|
151
|
+
f"Workspace name: {workspace_name}"
|
|
152
|
+
)
|
|
153
|
+
logger.error(error_msg)
|
|
154
|
+
raise Exception(error_msg) from e
|
|
155
|
+
except Exception as e:
|
|
156
|
+
# Re-raise the exception
|
|
157
|
+
raise e
|
|
158
|
+
|
|
159
|
+
# Update cross-database relations that require both databases to exist
|
|
160
|
+
await self._update_cross_database_relations()
|
|
143
161
|
|
|
144
162
|
# Save workspace metadata
|
|
145
163
|
self.save_database_ids()
|
|
@@ -334,19 +352,136 @@ class WorkspaceInitializer:
|
|
|
334
352
|
# This is a no-op but documents the intent
|
|
335
353
|
pass
|
|
336
354
|
|
|
355
|
+
async def _delete_existing_databases(self, parent: Page, database_ids: dict) -> None:
|
|
356
|
+
"""Delete all existing databases in the parent page.
|
|
357
|
+
|
|
358
|
+
Args:
|
|
359
|
+
parent: Parent page
|
|
360
|
+
database_ids: Dict of database IDs to delete
|
|
361
|
+
"""
|
|
362
|
+
import asyncio
|
|
363
|
+
|
|
364
|
+
deletion_tasks = []
|
|
365
|
+
for db_name, db_id in database_ids.items():
|
|
366
|
+
if db_id:
|
|
367
|
+
logger.info(f"Deleting {db_name} database ({db_id})...")
|
|
368
|
+
deletion_tasks.append(self._delete_database(db_id))
|
|
369
|
+
|
|
370
|
+
# Delete all databases concurrently
|
|
371
|
+
if deletion_tasks:
|
|
372
|
+
await asyncio.gather(*deletion_tasks, return_exceptions=True)
|
|
373
|
+
|
|
374
|
+
async def _delete_database(self, database_id: str) -> None:
|
|
375
|
+
"""Delete a single database.
|
|
376
|
+
|
|
377
|
+
Args:
|
|
378
|
+
database_id: ID of the database to delete
|
|
379
|
+
"""
|
|
380
|
+
try:
|
|
381
|
+
await self._client._api._request(
|
|
382
|
+
"DELETE",
|
|
383
|
+
f"/blocks/{database_id}"
|
|
384
|
+
)
|
|
385
|
+
logger.info(f"Deleted database {database_id}")
|
|
386
|
+
except Exception as e:
|
|
387
|
+
logger.warning(f"Failed to delete database {database_id}: {str(e)}")
|
|
388
|
+
# Continue with other deletions even if this one fails
|
|
389
|
+
|
|
337
390
|
async def _update_self_relations(self, database_id: str) -> None:
|
|
338
391
|
"""Update self-referential relations in Tasks database.
|
|
339
392
|
|
|
340
393
|
Note: The database was created with placeholder relations.
|
|
341
394
|
This method updates them to point to themselves.
|
|
342
395
|
"""
|
|
343
|
-
# Get the database
|
|
396
|
+
# Get the current database schema
|
|
344
397
|
db = await self._client.databases.get(database_id)
|
|
345
398
|
|
|
346
|
-
# Update Dependencies
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
399
|
+
# Update the Dependencies relation to point to itself
|
|
400
|
+
schema = db.schema
|
|
401
|
+
if "Dependencies" in schema:
|
|
402
|
+
schema["Dependencies"]["relation"]["database_id"] = database_id
|
|
403
|
+
|
|
404
|
+
# Update the database schema via API
|
|
405
|
+
await self._client._api._request(
|
|
406
|
+
"PATCH",
|
|
407
|
+
f"/databases/{database_id}",
|
|
408
|
+
json={"properties": schema}
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
logger.info(f"Updated self-referential relations for Tasks database {database_id}")
|
|
412
|
+
|
|
413
|
+
async def _update_cross_database_relations(self) -> None:
|
|
414
|
+
"""Update cross-database relations after all databases are created.
|
|
415
|
+
|
|
416
|
+
This updates:
|
|
417
|
+
- Tasks: Related Work Issue -> Work Issues
|
|
418
|
+
- Work Issues: Blocking Tasks -> Tasks
|
|
419
|
+
- Work Issues: Caused Incidents -> Incidents
|
|
420
|
+
- Incidents: Root Cause Work Issue -> Work Issues
|
|
421
|
+
"""
|
|
422
|
+
if "tasks" in self._database_ids:
|
|
423
|
+
await self._update_relation(
|
|
424
|
+
self._database_ids["tasks"],
|
|
425
|
+
"Related Work Issue",
|
|
426
|
+
self._database_ids.get("work_issues")
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
if "work_issues" in self._database_ids:
|
|
430
|
+
await self._update_relation(
|
|
431
|
+
self._database_ids["work_issues"],
|
|
432
|
+
"Blocking Tasks",
|
|
433
|
+
self._database_ids.get("tasks")
|
|
434
|
+
)
|
|
435
|
+
await self._update_relation(
|
|
436
|
+
self._database_ids["work_issues"],
|
|
437
|
+
"Caused Incidents",
|
|
438
|
+
self._database_ids.get("incidents")
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
if "incidents" in self._database_ids:
|
|
442
|
+
await self._update_relation(
|
|
443
|
+
self._database_ids["incidents"],
|
|
444
|
+
"Root Cause Work Issue",
|
|
445
|
+
self._database_ids.get("work_issues")
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
logger.info("Updated all cross-database relations")
|
|
449
|
+
|
|
450
|
+
async def _update_relation(
|
|
451
|
+
self,
|
|
452
|
+
database_id: str,
|
|
453
|
+
property_name: str,
|
|
454
|
+
target_database_id: Optional[str],
|
|
455
|
+
) -> None:
|
|
456
|
+
"""Update a relation property to point to the target database.
|
|
457
|
+
|
|
458
|
+
Args:
|
|
459
|
+
database_id: Database to update
|
|
460
|
+
property_name: Name of the relation property
|
|
461
|
+
target_database_id: Target database ID (if None, skip update)
|
|
462
|
+
"""
|
|
463
|
+
if not target_database_id:
|
|
464
|
+
logger.warning(f"Skipping {property_name} update: target database not found")
|
|
465
|
+
return
|
|
466
|
+
|
|
467
|
+
# Get the current database schema
|
|
468
|
+
db = await self._client.databases.get(database_id)
|
|
469
|
+
schema = db.schema
|
|
470
|
+
|
|
471
|
+
# Update the relation property
|
|
472
|
+
if property_name in schema:
|
|
473
|
+
schema[property_name]["relation"]["database_id"] = target_database_id
|
|
474
|
+
|
|
475
|
+
# Update the database schema via API
|
|
476
|
+
await self._client._api._request(
|
|
477
|
+
"PATCH",
|
|
478
|
+
f"/databases/{database_id}",
|
|
479
|
+
json={"properties": schema}
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
logger.info(f"Updated {property_name} relation to {target_database_id}")
|
|
483
|
+
else:
|
|
484
|
+
logger.warning(f"Property {property_name} not found in database {database_id}")
|
|
350
485
|
|
|
351
486
|
def save_database_ids(self, path: Optional[Path] = None) -> None:
|
|
352
487
|
"""Save workspace metadata (database IDs and workspace info) to config file.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: better-notion
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: A high-level Python SDK for the Notion API with developer experience in mind.
|
|
5
5
|
Project-URL: Homepage, https://github.com/nesalia-inc/better-notion
|
|
6
6
|
Project-URL: Documentation, https://github.com/nesalia-inc/better-notion#readme
|
|
@@ -130,11 +130,11 @@ better_notion/utils/agents/dependency_resolver.py,sha256=PfHHDIQztGih4LwylMb0_My
|
|
|
130
130
|
better_notion/utils/agents/metadata.py,sha256=thQSXfYx9mWgmBud8HtlNTLr5SwH6E_O1AjSNSnMFoo,6614
|
|
131
131
|
better_notion/utils/agents/project_context.py,sha256=aJlzy5H2rL4sAfW2jHL_3K2VkBJ4ihUhCRVolkpuO78,7477
|
|
132
132
|
better_notion/utils/agents/rbac.py,sha256=8ZA8Y7wbOiVZDbpjpH7iC35SZrZ0jl4fcJ3xWCm3SsE,11820
|
|
133
|
-
better_notion/utils/agents/schemas.py,sha256=
|
|
133
|
+
better_notion/utils/agents/schemas.py,sha256=EpAEevoth-DGWepGMubRFjdvHfe7zrQxi9i4CHDvem8,22946
|
|
134
134
|
better_notion/utils/agents/state_machine.py,sha256=xUBEeDTbU1Xq-rsRo2sbr6AUYpYrV9DTHOtZT2cWES8,6699
|
|
135
|
-
better_notion/utils/agents/workspace.py,sha256=
|
|
136
|
-
better_notion-2.1.
|
|
137
|
-
better_notion-2.1.
|
|
138
|
-
better_notion-2.1.
|
|
139
|
-
better_notion-2.1.
|
|
140
|
-
better_notion-2.1.
|
|
135
|
+
better_notion/utils/agents/workspace.py,sha256=9BRe_qGMjdyR9jaAkm9NCCovqWjeY429LE7mP1fyumo,21894
|
|
136
|
+
better_notion-2.1.2.dist-info/METADATA,sha256=TxRPM7kRzFEcT7oiAZDSmSmtQ0nOOd7Xi5xY4i1Z6sY,11096
|
|
137
|
+
better_notion-2.1.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
138
|
+
better_notion-2.1.2.dist-info/entry_points.txt,sha256=D0bUcP7Z00Zyjxw7r2p29T95UrwioDO0aGDoHe9I6fo,55
|
|
139
|
+
better_notion-2.1.2.dist-info/licenses/LICENSE,sha256=BAdN3JpgMY_y_fWqZSCFSvSbC2mTHP-BKDAzF5FXQAI,1069
|
|
140
|
+
better_notion-2.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|