|
34 | 34 | NoopProgressMonitor, |
35 | 35 | TqdmProgressMonitor, |
36 | 36 | ) |
37 | | -from ...query import QuerySpecification |
| 37 | +from ...query import DEFAULT_PAGE_SIZE, QueryContentMode, QuerySpecification |
38 | 38 | from ...sentinels import ( |
39 | 39 | NotSet, |
40 | 40 | NotSetType, |
@@ -98,6 +98,7 @@ class Dataset: |
98 | 98 |
|
99 | 99 | __roboto_client: RobotoClient |
100 | 100 | __record: DatasetRecord |
| 101 | + __content_mode: QueryContentMode |
101 | 102 | __file_service: FileService |
102 | 103 |
|
103 | 104 | @classmethod |
@@ -350,7 +351,7 @@ def query( |
350 | 351 | Found dataset: Other Roboto Test |
351 | 352 | """ |
352 | 353 | roboto_client = RobotoClient.defaulted(roboto_client) |
353 | | - spec = spec if spec is not None else QuerySpecification() |
| 354 | + spec = spec if spec is not None else QuerySpecification(limit=DEFAULT_PAGE_SIZE) |
354 | 355 |
|
355 | 356 | known = set(DatasetRecord.model_fields.keys()) |
356 | 357 | actual = set() |
@@ -386,17 +387,22 @@ def query( |
386 | 387 | def __eq__(self, other: object) -> bool: |
387 | 388 | if not isinstance(other, Dataset): |
388 | 389 | return False |
389 | | - return self.record == other.record |
| 390 | + |
| 391 | + # Only compare core dataset entity fields |
| 392 | + exclude_meta: dict[str, typing.Any] = {"metadata": dict()} |
| 393 | + return self.record.model_copy(update=exclude_meta) == other.record.model_copy(update=exclude_meta) |
390 | 394 |
|
391 | 395 | def __init__( |
392 | 396 | self, |
393 | 397 | record: DatasetRecord, |
394 | 398 | roboto_client: typing.Optional[RobotoClient] = None, |
395 | 399 | file_service: typing.Optional[FileService] = None, |
| 400 | + content_mode: typing.Optional[QueryContentMode] = None, |
396 | 401 | ) -> None: |
397 | 402 | self.__roboto_client = RobotoClient.defaulted(roboto_client) |
398 | 403 | self.__file_service = file_service or FileService(self.__roboto_client) |
399 | 404 | self.__record = record |
| 405 | + self.__content_mode = content_mode or QueryContentMode.RecordWithMeta |
400 | 406 |
|
401 | 407 | def __repr__(self) -> str: |
402 | 408 | return self.__record.model_dump_json() |
@@ -454,7 +460,26 @@ def metadata(self) -> dict[str, typing.Any]: |
454 | 460 | Returns a copy of the dataset's metadata dictionary containing arbitrary |
455 | 461 | key-value pairs for storing custom information. Supports nested structures |
456 | 462 | and dot notation for accessing nested fields. |
| 463 | +
|
| 464 | + Note: this attribute is kept for backward compatibility. Prefer :py:meth:`get_metadata()`, |
| 465 | + since metadata may need to be loaded on-demand from the server. |
457 | 466 | """ |
| 467 | + |
| 468 | + return self.get_metadata() |
| 469 | + |
| 470 | + def get_metadata(self) -> dict[str, typing.Any]: |
| 471 | + """Return custom metadata associated with this dataset. |
| 472 | +
|
| 473 | + Returns a copy of the dataset's metadata dictionary containing arbitrary |
| 474 | + key-value pairs for storing custom information. Supports nested structures |
| 475 | + and dot notation for accessing nested fields. |
| 476 | + """ |
| 477 | + |
| 478 | + if self.__content_mode is not QueryContentMode.RecordWithMeta: |
| 479 | + # Force metadata to be fetched from the DB. |
| 480 | + self.refresh() |
| 481 | + self.__content_mode = QueryContentMode.RecordWithMeta |
| 482 | + |
458 | 483 | return self.__record.metadata.copy() |
459 | 484 |
|
460 | 485 | @property |
@@ -552,7 +577,9 @@ def create_directory( |
552 | 577 | Create a directory with intermediate directories: |
553 | 578 |
|
554 | 579 | >>> directory = dataset.create_directory( |
555 | | - ... name="final", parent_path="path/to/deep", create_intermediate_dirs=True |
| 580 | + ... name="final", |
| 581 | + ... parent_path=pathlib.Path("path/to/deep"), |
| 582 | + ... create_intermediate_dirs=True, |
556 | 583 | ... ) |
557 | 584 | >>> print(directory.relative_path) |
558 | 585 | path/to/deep/final |
|
0 commit comments