-
Notifications
You must be signed in to change notification settings - Fork 28
fix(backend): create node with many rels faster #6883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,22 +2,21 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.core.migrations.graph.m003_relationship_parent_optional import Migration003, Migration003Query01 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.core.node import Node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.core.schema import SchemaRoot, internal_schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.core.schema.schema_branch import SchemaBranch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.core.utils import count_relationships | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.database import InfrahubDatabase | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@pytest.fixture | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def migration_003_data(db: InfrahubDatabase, reset_registry, default_branch, delete_all_nodes_in_db): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# # load the internal schema from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
schema = SchemaRoot(**internal_schema) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
schema_branch = SchemaBranch(cache={}, name="default_branch") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
schema_branch.load_schema(schema=schema) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
schema_branch.process() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node_schema = schema_branch.get(name="SchemaNode") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rel_schema = schema_branch.get(name="SchemaRelationship") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def migration_003_data( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
db: InfrahubDatabase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
reset_registry, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
default_branch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
delete_all_nodes_in_db, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
register_core_models_schema: SchemaBranch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node_schema = register_core_models_schema.get(name="SchemaNode") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rel_schema = register_core_models_schema.get(name="SchemaRelationship") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+11
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add return type and docstring; annotate untyped fixture params. Per guidelines, add -> None and annotate reset_registry/default_branch/delete_all_nodes_in_db. Include a brief Google-style docstring. Apply this diff: -async def migration_003_data(
- db: InfrahubDatabase,
- reset_registry,
- default_branch,
- delete_all_nodes_in_db,
- register_core_models_schema: SchemaBranch,
-):
+async def migration_003_data(
+ db: InfrahubDatabase,
+ reset_registry: Any,
+ default_branch: Any,
+ delete_all_nodes_in_db: Any,
+ register_core_models_schema: SchemaBranch,
+) -> None:
+ """Prepare data for Migration003.
+
+ Creates a Node with two Parent relationships (one optional, one required)
+ using the shared core models schema.
+
+ Args:
+ db: Database handle.
+ reset_registry: Ensures a clean registry.
+ default_branch: Ensures the default branch exists.
+ delete_all_nodes_in_db: Cleans DB prior to running the test.
+ register_core_models_schema: Registered schema branch containing core models.
+
+ Returns:
+ None
+ """ 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node1 = await Node.init(db=db, schema=node_schema) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await node1.new(db=db, name="Node", namespace="Test") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Confirm pytest async support and fixture availability.
Using async tests and an async fixture with @pytest.fixture requires pytest-asyncio or equivalent auto mode. Also verify that register_core_models_schema is defined as a fixture.
Run:
🏁 Script executed:
Length of output: 1469
🏁 Script executed:
Length of output: 1974
Ensure pytest-asyncio is enabled for async fixtures/tests
I verified that:
asyncio_mode
orpytest.mark.asyncio
entry in your pytest config (pytest.ini/pyproject.toml/conftest.py).migration_003_data
and async tests inbackend/tests/unit/core/migrations/graph/test_003.py
will not run without the pytest-asyncio plugin or equivalent.register_core_models_schema
fixture is correctly defined as an async fixture inbackend/tests/conftest.py
.Please update your test setup to support asyncio, for example:
Add
pytest-asyncio
to your dev dependencies.In
pytest.ini
orpyproject.toml
, enable asyncio mode:or
(Alternatively) add at the top of your async test module:
This will ensure
async def
fixtures and tests execute correctly.🤖 Prompt for AI Agents