dabla commented on code in PR #77435: URL: https://github.com/apache/airflow/pull/77435#discussion_r4667525866
########## providers/common/io/docs/changelog.rst: ########## @@ -26,6 +26,10 @@ Changelog --------- .. note:: + ``StateStoreObjectStorageBackend`` now raises ``ValueError`` when ``[common.io] state_store_objectstorage_path`` + has no URL scheme (for example ``/tmp/task-state``). Before, large values were written but reading them back + failed with ``JSONDecodeError``. Set the path to a URL such as ``s3://conn_id@bucket/task-state``, or + ``file:///path/to/task-state`` for local storage. Review Comment: **[nit]** The two notes render as one paragraph, and the note leaves out the calls that worked before. There is no blank line between this note and the `XComObjectStorageBackend` one below it, so reStructuredText joins them into a single paragraph. A blank line (or a bullet per backend) keeps them apart. The note also says that reading failed before. That holds for the worker path (`serialize_*_to_ref` / `deserialize_*_from_ref`). The plain `get` / `set` / `delete` / `clear` calls round-tripped fine with a path such as `/tmp/task-state` (on `fecbb16aa0`: `set(scope, "k", "hello")` then `get(scope, "k")` returns `"hello"`), and they raise now too. The PR body says so; one sentence here would tell a user who runs the backend through `[state_store] backend` why a setup that worked now fails. ########## providers/common/io/src/airflow/providers/common/io/state_store/backend.py: ########## @@ -47,7 +47,14 @@ @cache def _get_base_path() -> ObjectStoragePath: - return ObjectStoragePath(conf.get_mandatory_value(SECTION, "state_store_objectstorage_path")) + path = conf.get_mandatory_value(SECTION, "state_store_objectstorage_path") + # _is_storage_ref only recognises URLs, so a schemeless ref would be parsed as JSON on read. + if not urlsplit(path).scheme: Review Comment: **[warning]** The read path swallows the new error and still ends in `JSONDecodeError`. (The lines concerned, [`_is_storage_ref` at 128-134](https://github.com/apache/airflow/blob/496131908df8fccc1991b0a01c68561a76d13026/providers/common/io/src/airflow/providers/common/io/state_store/backend.py#L128-L134), are not in the diff.) `_is_storage_ref` calls `_get_base_path()` inside `try: ... except Exception: return False`. With a path without a scheme, the new `ValueError` is caught there, the reference is taken for an inline value, and `deserialize_task_state_store_from_ref` / `deserialize_asset_state_store_from_ref` pass it to `json.loads`. A reader whose path is misconfigured therefore still gets the error this PR sets out to replace, and the message that names the setting never shows. Checked on this head with a reference written under `file:///tmp/x/store`: | reader's `state_store_objectstorage_path` | `fecbb16aa0` (base) | this head | | --- | --- | --- | | `""` | `JSONDecodeError` | `JSONDecodeError` | | `/tmp/x/store` | returns `{"k": "v"}` | `JSONDecodeError` | The second row worked before, because `ObjectStoragePath("/tmp/x/store")` compares equal to the `file://` form in `is_relative_to`; it now fails, and with the unclear error. Resolving the base path outside the `try` would let the `ValueError` through on reads as well: ```python def _is_storage_ref(value: str) -> bool: base_path = _get_base_path() try: if not urlsplit(value).scheme: return False return ObjectStoragePath(value).is_relative_to(base_path) except Exception: return False ``` A parametrized test over the two `deserialize_*_from_ref` methods with a URL reference and a path without a scheme would pin it; the test added here only goes through `serialize_task_state_store_to_ref`. ("Errors should never pass silently", [PEP 20](https://peps.python.org/pep-0020/).) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
