-
Notifications
You must be signed in to change notification settings - Fork 33
Lock names include attributes values #6888
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
base: stable
Are you sure you want to change the base?
Changes from all commits
cee5352
37296d5
b2f1227
3f7cc12
8496ad8
b38db02
1b732ad
64d84b7
1488cf8
74f0995
254153c
746a0d1
818e670
f7728f4
3aa9ba8
9eefa2f
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -257,7 +257,13 @@ async def init( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return cls(**attrs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def handle_pool(self, db: InfrahubDatabase, attribute: BaseAttribute, errors: list) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def handle_pool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
db: InfrahubDatabase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
attribute: BaseAttribute, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
errors: list, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
allocate_resources: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+260
to
+266
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 | 🟠 Major Update docstring to document The method signature now includes As per coding guidelines Apply this diff to update the docstring: async def handle_pool(
self,
db: InfrahubDatabase,
attribute: BaseAttribute,
errors: list,
allocate_resources: bool = True,
) -> None:
- """Evaluate if a resource has been requested from a pool and apply the resource
+ """Evaluate if a resource has been requested from a pool and apply the resource.
+
+ Args:
+ db: Database connection.
+ attribute: Attribute to evaluate for pool allocation.
+ errors: List to append validation errors.
+ allocate_resources: Whether to perform pool allocation; when False, pool allocation is skipped.
This method only works on number pools, currently Integer is the only type that has the from_pool
within the create code.
""" 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Evaluate if a resource has been requested from a pool and apply the resource | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
This method only works on number pools, currently Integer is the only type that has the from_pool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -268,7 +274,7 @@ async def handle_pool(self, db: InfrahubDatabase, attribute: BaseAttribute, erro | |||||||||||||||||||||||||||||||||||||||||||||||||||||
attribute.from_pool = {"id": attribute.schema.parameters.number_pool_id} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
attribute.is_default = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if not attribute.from_pool: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if not attribute.from_pool or not allocate_resources: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -426,7 +432,12 @@ async def handle_object_template(self, fields: dict, db: InfrahubDatabase, error | |||||||||||||||||||||||||||||||||||||||||||||||||||||
elif relationship_peers := await relationship.get_peers(db=db): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
fields[relationship_name] = [{"id": peer_id} for peer_id in relationship_peers] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def _process_fields(self, fields: dict, db: InfrahubDatabase) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def _process_fields( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
fields: dict, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
db: InfrahubDatabase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
process_pools: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
errors = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if "_source" in fields.keys(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -480,7 +491,7 @@ async def _process_fields(self, fields: dict, db: InfrahubDatabase) -> None: | |||||||||||||||||||||||||||||||||||||||||||||||||||||
# Generate Attribute and Relationship and assign them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
# ------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
errors.extend(await self._process_fields_relationships(fields=fields, db=db)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
errors.extend(await self._process_fields_attributes(fields=fields, db=db)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
errors.extend(await self._process_fields_attributes(fields=fields, db=db, process_pools=process_pools)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if errors: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValidationError(errors) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -517,7 +528,12 @@ async def _process_fields_relationships(self, fields: dict, db: InfrahubDatabase | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def _process_fields_attributes(self, fields: dict, db: InfrahubDatabase) -> list[ValidationError]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def _process_fields_attributes( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
fields: dict, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
db: InfrahubDatabase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
process_pools: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> list[ValidationError]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
errors: list[ValidationError] = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
for attr_schema in self._schema.attributes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -542,9 +558,15 @@ async def _process_fields_attributes(self, fields: dict, db: InfrahubDatabase) - | |||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if not self._existing: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
attribute: BaseAttribute = getattr(self, attr_schema.name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
await self.handle_pool(db=db, attribute=attribute, errors=errors) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
await self.handle_pool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
db=db, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
attribute=attribute, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
errors=errors, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
allocate_resources=process_pools, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
attribute.validate(value=attribute.value, name=attribute.name, schema=attribute.schema) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if process_pools or attribute.from_pool is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
attribute.validate(value=attribute.value, name=attribute.name, schema=attribute.schema) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
except ValidationError as exc: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
errors.append(exc) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -672,7 +694,13 @@ async def process_label(self, db: InfrahubDatabase | None = None) -> None: # no | |||||||||||||||||||||||||||||||||||||||||||||||||||||
self.label.value = " ".join([word.title() for word in self.name.value.split("_")]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.label.is_default = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def new(self, db: InfrahubDatabase, id: str | None = None, **kwargs: Any) -> Self: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
db: InfrahubDatabase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
id: str | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
process_pools: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
**kwargs: Any, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> Self: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+697
to
+703
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 | 🟠 Major Update docstring to document The As per coding guidelines Apply this diff to add a docstring: async def new(
self,
db: InfrahubDatabase,
id: str | None = None,
process_pools: bool = True,
**kwargs: Any,
) -> Self:
+ """Create a new node instance with the provided data.
+
+ Args:
+ db: Database connection.
+ id: Optional UUID for the node; generated if not provided.
+ process_pools: Whether to perform resource pool allocations; when False, pool allocation is skipped.
+ **kwargs: Field values for the node.
+
+ Returns:
+ The initialized node instance.
+ """
if id and not is_valid_uuid(id): 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if id and not is_valid_uuid(id): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValidationError({"id": f"{id} is not a valid UUID"}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if id: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -682,7 +710,7 @@ async def new(self, db: InfrahubDatabase, id: str | None = None, **kwargs: Any) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.id = id or str(UUIDT()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
await self._process_fields(db=db, fields=kwargs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
await self._process_fields(db=db, fields=kwargs, process_pools=process_pools) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
await self._process_macros(db=db) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -935,15 +963,29 @@ async def to_graphql( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return response | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def from_graphql(self, data: dict, db: InfrahubDatabase) -> bool: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Update object from a GraphQL payload.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def from_graphql( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
data: dict, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
db: InfrahubDatabase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
process_pools: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> bool: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Update object from a GraphQL payload. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
data: GraphQL payload to apply. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
db: Database connection used for related lookups. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
process_pools: Whether resource pool allocations should be performed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
True if any field changed, otherwise False. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
changed = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
for key, value in data.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if key in self._attributes and isinstance(value, dict): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
attribute = getattr(self, key) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
changed |= await attribute.from_graphql(data=value, db=db) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
changed |= await attribute.from_graphql(data=value, db=db, process_pools=process_pools) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if key in self._relationships: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
rel: RelationshipManager = getattr(self, key) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,57 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from collections.abc import Sequence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub import lock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.core.branch import Branch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.core.constraint.node.runner import NodeConstraintRunner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.core.node import Node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.database import InfrahubDatabase | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.lock import InfrahubMultiLock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from infrahub.lock_getter import get_lock_names_on_object_mutation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def run_constraints_and_save( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node: Node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node_constraint_runner: NodeConstraintRunner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fields_to_validate: list[str], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fields_to_save: list[str], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
db: InfrahubDatabase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
branch: Branch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
skip_uniqueness_check: bool = False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lock_names: Sequence[str] | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
manage_lock: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Validate a node and persist it, optionally reusing an existing lock context. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node: The node instance to validate and persist. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node_constraint_runner: Runner executing node-level constraints. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fields_to_validate: Field names that must be validated. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fields_to_save: Field names that must be persisted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
db: Database connection or transaction to use for persistence. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
branch: Branch associated with the mutation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
skip_uniqueness_check: Whether to skip uniqueness constraints. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lock_names: Precomputed lock identifiers to reuse when ``manage_lock`` is False. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
manage_lock: Whether this helper should acquire and release locks itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+12
to
+35
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 | 🟠 Major Add Raises section to docstring. The docstring is missing a Apply this diff: Args:
node: The node instance to validate and persist.
node_constraint_runner: Runner executing node-level constraints.
fields_to_validate: Field names that must be validated.
fields_to_save: Field names that must be persisted.
db: Database connection or transaction to use for persistence.
branch: Branch associated with the mutation.
skip_uniqueness_check: Whether to skip uniqueness constraints.
lock_names: Precomputed lock identifiers to reuse when ``manage_lock`` is False.
manage_lock: Whether this helper should acquire and release locks itself.
+
+ Raises:
+ ValueError: When manage_lock is False but lock_names is not provided.
""" 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if not manage_lock and lock_names is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError("lock_names must be provided when manage_lock is False") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
schema_branch = db.schema.get_schema_branch(name=branch.name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
locks = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
list(lock_names) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if lock_names is not None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else get_lock_names_on_object_mutation(node=node, schema_branch=schema_branch) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def _persist() -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await node_constraint_runner.check( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node=node, field_filters=fields_to_validate, skip_uniqueness_check=skip_uniqueness_check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await node.save(db=db, fields=fields_to_save) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if manage_lock: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async with InfrahubMultiLock(lock_registry=lock.registry, locks=locks): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await _persist() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await _persist() |
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.
🛠️ Refactor suggestion | 🟠 Major
Update docstring to document parameters.
The
from_graphql
method signature now includesprocess_pools: bool = True
, but the docstring (line 587) is brief and does not document any parameters. Please update the docstring to include anArgs
section documenting thedata
,db
, andprocess_pools
parameters, as well as aReturns
section.As per coding guidelines
Apply this diff to update the docstring:
📝 Committable suggestion
🤖 Prompt for AI Agents