Skip to content

Commit

Permalink
Add ability to filter on external ID for nodes even when no other fil…
Browse files Browse the repository at this point in the history
…ter properties are present (#356)

* Add ability to filter on external ID for nodes even when no other filter properties are present

* Fix tests

* Bump version and update changelog

* Regenerate examples
  • Loading branch information
MortGron authored Nov 15, 2024
1 parent eb738e6 commit 0a28ef7
Show file tree
Hide file tree
Showing 26 changed files with 67 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cognite/pygen/_core/templates/data_class_node.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,9 @@ class _{{ data_class.query_cls_name }}(NodeQueryCore[T_DomainModelList, {{ data_
connection_name="{{ field.name }}",{% if field.is_reverse_direct_relation and field.reverse_property.is_one_to_many %}
connection_type="reverse-list",{% endif %}
){% endif %}
{% endfor %}{% if data_class.has_filtering_fields %}
{% endfor %}
self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"]){% for field in data_class.filtering_fields %}
self.external_id = StringFilter(self, ["node", "externalId"]){% if data_class.has_filtering_fields %}{% for field in data_class.filtering_fields %}
self.{{ field.name }} = {{ field.filtering_cls }}(self, self._view_id.as_property_ref("{{ field.prop_name }}")){% endfor %}
self._filter_classes.extend([
self.space,
Expand Down
2 changes: 1 addition & 1 deletion cognite/pygen/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.99.48"
__version__ = "0.99.49"
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [0.99.48] - 24-11-14
### Fixed
- Add ability to filter on node external ID and space even when no other filterable properties are present.

## [0.99.48] - 24-11-13
### Changed
- [Experimental feature] Generic query split into three methods `.list()`, `.search()`, and `.aggregate(...)`.
Expand Down
4 changes: 2 additions & 2 deletions examples/cognite_core/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CogniteCoreClient:
CogniteCoreClient
Generated with:
pygen = 0.99.48
pygen = 0.99.49
cognite-sdk = 7.64.12
pydantic = 2.9.2
Expand All @@ -68,7 +68,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig):
else:
raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}")
# The client name is used for aggregated logging of Pygen Usage
client.config.client_name = "CognitePygen:0.99.48"
client.config.client_name = "CognitePygen:0.99.49"

self._client = client

Expand Down
3 changes: 3 additions & 0 deletions examples/cognite_core/data_classes/_cognite_cube_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,9 @@ def __init__(
connection_name="top",
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_cognite_cube_map(self, limit: int = DEFAULT_QUERY_LIMIT) -> CogniteCubeMapList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/cognite_core/data_classes/_cognite_visualizable.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ def __init__(
connection_name="object_3d",
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_cognite_visualizable(self, limit: int = DEFAULT_QUERY_LIMIT) -> CogniteVisualizableList:
return self._list(limit=limit)

Expand Down
4 changes: 2 additions & 2 deletions examples/equipment_unit/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EquipmentUnitClient:
EquipmentUnitClient
Generated with:
pygen = 0.99.48
pygen = 0.99.49
cognite-sdk = 7.64.12
pydantic = 2.9.2
Expand All @@ -41,7 +41,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig):
else:
raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}")
# The client name is used for aggregated logging of Pygen Usage
client.config.client_name = "CognitePygen:0.99.48"
client.config.client_name = "CognitePygen:0.99.49"

self._client = client

Expand Down
4 changes: 2 additions & 2 deletions examples/omni/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class OmniClient:
OmniClient
Generated with:
pygen = 0.99.48
pygen = 0.99.49
cognite-sdk = 7.64.12
pydantic = 2.9.2
Expand All @@ -59,7 +59,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig):
else:
raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}")
# The client name is used for aggregated logging of Pygen Usage
client.config.client_name = "CognitePygen:0.99.48"
client.config.client_name = "CognitePygen:0.99.49"

self._client = client

Expand Down
3 changes: 3 additions & 0 deletions examples/omni/data_classes/_cdf_external_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ def __init__(
reverse_expression,
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_cdf_external_reference(self, limit: int = DEFAULT_QUERY_LIMIT) -> CDFExternalReferencesList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/omni/data_classes/_cdf_external_references_listed.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ def __init__(
reverse_expression,
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_cdf_external_references_listed(self, limit: int = DEFAULT_QUERY_LIMIT) -> CDFExternalReferencesListedList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/omni/data_classes/_connection_item_c_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ def __init__(
connection_name="connection_item_b",
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_connection_item_c_node(self, limit: int = DEFAULT_QUERY_LIMIT) -> ConnectionItemCNodeList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/omni/data_classes/_primitive_nullable_listed.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ def __init__(
reverse_expression,
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_primitive_nullable_listed(self, limit: int = DEFAULT_QUERY_LIMIT) -> PrimitiveNullableListedList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/omni/data_classes/_primitive_required_listed.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ def __init__(
reverse_expression,
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_primitive_required_listed(self, limit: int = DEFAULT_QUERY_LIMIT) -> PrimitiveRequiredListedList:
return self._list(limit=limit)

Expand Down
4 changes: 2 additions & 2 deletions examples/omni_multi/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class OmniMultiClient:
OmniMultiClient
Generated with:
pygen = 0.99.48
pygen = 0.99.49
cognite-sdk = 7.64.12
pydantic = 2.9.2
Expand All @@ -125,7 +125,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig):
else:
raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}")
# The client name is used for aggregated logging of Pygen Usage
client.config.client_name = "CognitePygen:0.99.48"
client.config.client_name = "CognitePygen:0.99.49"

self.omni_multi_a = OmniMultiAAPIs(client)
self.omni_multi_b = OmniMultiBAPIs(client)
Expand Down
4 changes: 2 additions & 2 deletions examples/omni_sub/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OmniSubClient:
OmniSubClient
Generated with:
pygen = 0.99.48
pygen = 0.99.49
cognite-sdk = 7.64.12
pydantic = 2.9.2
Expand All @@ -41,7 +41,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig):
else:
raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}")
# The client name is used for aggregated logging of Pygen Usage
client.config.client_name = "CognitePygen:0.99.48"
client.config.client_name = "CognitePygen:0.99.49"

self._client = client

Expand Down
3 changes: 3 additions & 0 deletions examples/omni_sub/data_classes/_connection_item_c_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ def __init__(
connection_name="connection_item_b",
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_connection_item_c_node(self, limit: int = DEFAULT_QUERY_LIMIT) -> ConnectionItemCNodeList:
return self._list(limit=limit)

Expand Down
4 changes: 2 additions & 2 deletions examples/scenario_instance/client/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ScenarioInstanceClient:
ScenarioInstanceClient
Generated with:
pygen = 0.99.48
pygen = 0.99.49
cognite-sdk = 7.64.12
pydantic = 2.9.2
Expand All @@ -39,7 +39,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig):
else:
raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}")
# The client name is used for aggregated logging of Pygen Usage
client.config.client_name = "CognitePygen:0.99.48"
client.config.client_name = "CognitePygen:0.99.49"

self._client = client

Expand Down
4 changes: 2 additions & 2 deletions examples/windmill/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WindmillClient:
WindmillClient
Generated with:
pygen = 0.99.48
pygen = 0.99.49
cognite-sdk = 7.64.12
pydantic = 2.9.2
Expand All @@ -49,7 +49,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig):
else:
raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}")
# The client name is used for aggregated logging of Pygen Usage
client.config.client_name = "CognitePygen:0.99.48"
client.config.client_name = "CognitePygen:0.99.49"

self._client = client

Expand Down
3 changes: 3 additions & 0 deletions examples/windmill/data_classes/_gearbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ def __init__(
reverse_expression,
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_gearbox(self, limit: int = DEFAULT_QUERY_LIMIT) -> GearboxList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/windmill/data_classes/_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ def __init__(
reverse_expression,
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_generator(self, limit: int = DEFAULT_QUERY_LIMIT) -> GeneratorList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/windmill/data_classes/_high_speed_shaft.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ def __init__(
reverse_expression,
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_high_speed_shaft(self, limit: int = DEFAULT_QUERY_LIMIT) -> HighSpeedShaftList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/windmill/data_classes/_main_shaft.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ def __init__(
reverse_expression,
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_main_shaft(self, limit: int = DEFAULT_QUERY_LIMIT) -> MainShaftList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/windmill/data_classes/_nacelle.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ def __init__(
connection_name="power_inverter",
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_nacelle(self, limit: int = DEFAULT_QUERY_LIMIT) -> NacelleList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/windmill/data_classes/_power_inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ def __init__(
reverse_expression,
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_power_inverter(self, limit: int = DEFAULT_QUERY_LIMIT) -> PowerInverterList:
return self._list(limit=limit)

Expand Down
3 changes: 3 additions & 0 deletions examples/windmill/data_classes/_rotor.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ def __init__(
reverse_expression,
)

self.space = StringFilter(self, ["node", "space"])
self.external_id = StringFilter(self, ["node", "externalId"])

def list_rotor(self, limit: int = DEFAULT_QUERY_LIMIT) -> RotorList:
return self._list(limit=limit)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cognite-pygen"
version = "0.99.48"
version = "0.99.49"
description = "Cognite Python SDK Generator"
readme = "README.md"
authors = ["Cognite <[email protected]>"]
Expand Down

0 comments on commit 0a28ef7

Please sign in to comment.