`ExportObjectResultMetadata.validate_uri()` includes commented out code as a remark for the reader that short term exports need not to have a URI as part of their result metadata. Remove this remark.
Co-authored-by: David López <46503462+davelopez@users.noreply.github.com>
[PEP 706](https://peps.python.org/pep-0706/), first implemented in Python
3.11.4, mitigates some of the security issues of `TarFile.extract()` and
`TarFile.extractall()` by allowing to specify a `filter` keyword-only
parameter.
Set a safe default (`data_filter`) for the filter if available,
reverting to Python 3.11 behavior ('fully_trusted') otherwise, see
https://docs.python.org/3/library/tarfile.html#supporting-older-python-versions
Also:
- Remove unused `tar` parameter from `upload_tar()`
This will workaround an issue with jinja templates rendering a field composed only by numbers to be considered a number when the field is of type string, causing the config model validation to fail. Trying to cast the value to string using the jinja template itself did not work.
Write the actual URIs where files are saved to by file sources to a new `uri` field of the `ExportObjectResultMetadata` model. Restore behavior before commit 53012bf, namely setting the history export request metadata before attempting the export.
---
Before applying the set of changes from 53012bf, the method `ModelStoreManager.set_history_export_request_metadata()` instantiates a `ExportObjectMetadata` Pydantic model and dumps it to the database in the form of JSON as the field `StoreExportAssociation.export_metadata`. After the export is complete, the method `set_history_export_result_metadata()` takes the same instance of `ExportObjectMetadata`, instantiates a `ExportObjectResultMetadata` Pydantic model, sets it as the `result_data` of the `ExportObjectMetadata` instance, and then saves the `ExportObjectMetadata` Pydantic model in the form of JSON to the database again.
After applying the set of changes, the call to `ModelStoreManager.set_history_export_request_metadata()` is delayed until the file has already been saved to the file source, as the actual URI that the file source assigns to the file is otherwise unknown.
The URI assigned by the file source overwrites the original target URI in the request. This involves a slight deviation from the previous behavior: if for example, power gets cut at the right time, `StoreExportAssociation.export_metadata` may not exist despite the history having been already saved to the file source, because database writes happen within the `finally:` block.
Moreover, overwriting the original target URI from the request is formally wrong, because the actual URI assigned by the file source should be part of the export result metadata, as it becomes known when the export completes.
This commit addresses these issues by adding a new field `uri` to the `ExportObjectResultMetadata` model, where the actual URI the file has been saved to by the file source is written. Backwards compatibility is ensured via `HistoriesService._get_export_record_data()`, which retrieves the new field when available and otherwise uses `ExportObjectRequestMetadata.payload.target_uri` (given that `ExportObjectRequestMetadata.payload` is of type `WriteStoreToPayload`).
That's a much better consumer experience. A model generated for
gx_conditional.xml would look like
```typescript
export type ConditionalType =
| WhenTestParameterA
| WhenTestParameterB
| WhenTestParameterC
export type TestParameter = "a"
export type IntegerParameter = number
export type TestParameter1 = "b"
export type BooleanParameter = boolean
export type TestParameter2 = "c"
export type ColorParameter = string
export interface MySchema {
conditional_parameter: ConditionalType
}
export interface WhenTestParameterA {
test_parameter: TestParameter
integer_parameter: IntegerParameter
}
export interface WhenTestParameterB {
test_parameter: TestParameter1
boolean_parameter: BooleanParameter
}
export interface WhenTestParameterC {
test_parameter: TestParameter2
color_parameter: ColorParameter
}
```
instead of
```typescript
export type ConditionalType =
| WhenTestParameterA
| WhenTestParameterB
| WhenTestParameterC
export type TestParameter = string | boolean
export type IntegerParameter = number
export type TestParameter1 = string | boolean
export type BooleanParameter = boolean
export type TestParameter2 = string | boolean
export type ColorParameter = string
export interface MySchema {
conditional_parameter: ConditionalType
}
export interface WhenTestParameterA {
test_parameter: TestParameter
integer_parameter: IntegerParameter
}
export interface WhenTestParameterB {
test_parameter: TestParameter1
boolean_parameter: BooleanParameter
}
export interface WhenTestParameterC {
test_parameter: TestParameter2
color_parameter: ColorParameter
}
```
With the new model I can write an input object without looking at the
tool source, with the previous one I don't know what string I would need
to supply.