Skip to content

Update docs on list() and retrieve() to make it clearer to users how to get additional properties specified on views. #2180

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

davidaschneider
Copy link

Description

Clear up confusion experienced by multiple newcomers to the API about how to retrieve properties specified on a view when using the list() and retrieve() methods in the cognite.client.data_classes.data_modeling.instances API.

There is one statement here that could use some assistance from someone who has a better understanding of what actually happens:

If not specified, only basic fields common to all instances will be retrieved

Any suggests for better wording would be welcome.

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • Changelog updated in CHANGELOG.md.
  • Version bumped. If triggering a new release is desired, bump the version number in _version.py and pyproject.toml per semantic versioning.

…to get additional properties specified on views.
Copy link

codecov bot commented Jun 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.71%. Comparing base (a9d591a) to head (c58954d).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2180      +/-   ##
==========================================
+ Coverage   90.65%   90.71%   +0.05%     
==========================================
  Files         159      162       +3     
  Lines       24135    24372     +237     
==========================================
+ Hits        21880    22109     +229     
- Misses       2255     2263       +8     
Files with missing lines Coverage Δ
cognite/client/_api/data_modeling/instances.py 88.29% <ø> (ø)

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


Args:
nodes (NodeId | Sequence[NodeId] | tuple[str, str] | Sequence[tuple[str, str]] | None): Node ids
edges (EdgeId | Sequence[EdgeId] | tuple[str, str] | Sequence[tuple[str, str]] | None): Edge ids
sources (Source | Sequence[Source] | None): Retrieve properties from the listed - by reference - views.
sources (Source | Sequence[Source] | None): Governs which views to retrieve properties through. Only properties specified on the provided views will be retrieved. If not specified, only base properties (space, external id, type, ...) will be retrieved. Connection properties (edges and reverse direct properties, see https://docs.cognite.com/cdf/dm/dm_concepts/dm_containers_views_datamodels#connection-properties) can not be retrieved/traversed using this method; use the `query` method instead.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sources (Source | Sequence[Source] | None): Governs which views to retrieve properties through. Only properties specified on the provided views will be retrieved. If not specified, only base properties (space, external id, type, ...) will be retrieved. Connection properties (edges and reverse direct properties, see https://docs.cognite.com/cdf/dm/dm_concepts/dm_containers_views_datamodels#connection-properties) can not be retrieved/traversed using this method; use the `query` method instead.
sources (Source | Sequence[Source] | None): Governs which views to retrieve properties through. If not specified, only base properties (space, external id, type, ...) will be retrieved. `Connection properties <https://docs.cognite.com/cdf/dm/dm_concepts/dm_containers_views_datamodels#connection-properties>`_) cannot be retrieved/traversed using this method; use the `query` method instead.

@@ -1612,7 +1612,7 @@ def list(
Args:
instance_type (Literal['node', 'edge'] | type[T_Node] | type[T_Edge]): Whether to query for nodes or edges. You can also pass a custom typed node (or edge class) inheriting from TypedNode (or TypedEdge). See apply, retrieve_nodes or retrieve_edges for an example.
include_typing (bool): Whether to return property type information as part of the result.
sources (Source | Sequence[Source] | None): Views to retrieve properties from.
sources (Source | Sequence[Source] | None): Governs which views to retrieve properties through. Only properties specified on the provided views will be retrieved. If not specified, only base properties (space, external id, type, ...) will be retrieved. Connection properties (edges and reverse direct properties, see https://docs.cognite.com/cdf/dm/dm_concepts/dm_containers_views_datamodels#connection-properties) can not be retrieved/traversed using this method; use the `query` method instead.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sources (Source | Sequence[Source] | None): Governs which views to retrieve properties through. Only properties specified on the provided views will be retrieved. If not specified, only base properties (space, external id, type, ...) will be retrieved. Connection properties (edges and reverse direct properties, see https://docs.cognite.com/cdf/dm/dm_concepts/dm_containers_views_datamodels#connection-properties) can not be retrieved/traversed using this method; use the `query` method instead.
sources (Source | Sequence[Source] | None): Governs which views to retrieve properties through. If not specified, only base properties (space, external id, type, ...) will be retrieved. `Connection properties <https://docs.cognite.com/cdf/dm/dm_concepts/dm_containers_views_datamodels#connection-properties>`_) cannot be retrieved/traversed using this method; use the `query` method instead.

@erlendvollset erlendvollset requested a review from arnekv June 30, 2025 14:29
@erlendvollset
Copy link
Collaborator

Requesting input from @arnekv on exact wording here.

@davidaschneider
Copy link
Author

As I mentioned on slack to @erlendvollset , the parts he's proposing to remove are parts that would have clarified the problem to newbies like me and Akshat. We sort of understood in principle that we'd only get the properties specified on the view, but actually saying that explicitly in the docs would have made it much clearer to both of us. Likewise, explicitly saying what kinds of properties are not returned (rather than making the user follow a link to a place where they're still not terribly explicit) is much more helpful to the uninitiated.

Dave Schneider added 2 commits June 30, 2025 12:35
…mples of connection properties. In fact, they're currently the only examples, but that could theoretically change.
…uld be used to retrieve ReverseDirectRelations, since there are multiple 'query' functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants