MonkeyCanCode commented on PR #3016:
URL: https://github.com/apache/polaris/pull/3016#issuecomment-3507723321
Here is the full diff between the new code and old code:
```
➜ polaris git:(fix_monkey_patching) diff -r client/python/apache_polaris
~/Desktop/current/polaris/client/python/apache_polaris
diff --color -r client/python/apache_polaris/cli/polaris_cli.py
/Users/yong/Desktop/old/polaris/client/python/apache_polaris/cli/polaris_cli.py
49a50,90
> def _patch_generated_models() -> None:
> """
> The OpenAPI generator creates an `api_client` that dynamically
looks up
> model classes from the `apache_polaris.sdk.catalog.models` module
using `getattr()`.
> For example, when a response for a `create_policy` call is
received, the
> deserializer tries to find the `LoadPolicyResponse` class by
looking for
> `apache_polaris.sdk.catalog.models.LoadPolicyResponse`.
>
> However, the generator fails to add the necessary `import`
statements
> to the `apache_polaris/sdk/catalog/models/__init__.py` file. This
means that even
> though the model files exist (e.g., `load_policy_response.py`),
the classes
> are not part of the `apache_polaris.sdk.catalog.models` namespace.
>
> This method works around the bug in the generated code without
modifying
> the source files. It runs once per CLI execution, before any
commands, and
> manually injects the missing response-side model classes into the
> `apache_polaris.sdk.catalog.models` namespace, allowing the
deserializer to find them.
> """
> import apache_polaris.sdk.catalog.models
> from apache_polaris.sdk.catalog.models.applicable_policy import
ApplicablePolicy
> from
apache_polaris.sdk.catalog.models.get_applicable_policies_response import
GetApplicablePoliciesResponse
> from apache_polaris.sdk.catalog.models.list_policies_response
import ListPoliciesResponse
> from apache_polaris.sdk.catalog.models.load_policy_response import
LoadPolicyResponse
> from apache_polaris.sdk.catalog.models.policy import Policy
> from apache_polaris.sdk.catalog.models.policy_attachment_target
import PolicyAttachmentTarget
> from apache_polaris.sdk.catalog.models.policy_identifier import
PolicyIdentifier
>
> models_to_patch = {
> "ApplicablePolicy": ApplicablePolicy,
> "GetApplicablePoliciesResponse": GetApplicablePoliciesResponse,
> "ListPoliciesResponse": ListPoliciesResponse,
> "LoadPolicyResponse": LoadPolicyResponse,
> "Policy": Policy,
> "PolicyAttachmentTarget": PolicyAttachmentTarget,
> "PolicyIdentifier": PolicyIdentifier,
> }
>
> for name, model_class in models_to_patch.items():
> setattr(apache_polaris.sdk.catalog.models, name, model_class)
>
> @staticmethod
50a92
> PolarisCli._patch_generated_models()
diff --color -r client/python/apache_polaris/sdk/catalog/models/__init__.py
/Users/yong/Desktop/old/polaris/client/python/apache_polaris/sdk/catalog/models/__init__.py
19a20,34
> # coding: utf-8
>
> # flake8: noqa
> """
> Apache Iceberg REST Catalog API
>
> Defines the specification for the first version of the REST Catalog
API. Implementations should ideally support both Iceberg table specs v1 and v2,
with priority given to v2.
>
> The version of the OpenAPI document: 0.0.1
> Generated by OpenAPI Generator (https://openapi-generator.tech)
>
> Do not edit the class manually.
> """ # noqa: E501
>
> # import models into model package
27d41
< from apache_polaris.sdk.catalog.models.applicable_policy import
ApplicablePolicy
39d52
< from apache_polaris.sdk.catalog.models.attach_policy_request import
AttachPolicyRequest
53d65
< from apache_polaris.sdk.catalog.models.create_generic_table_request import
CreateGenericTableRequest
56d67
< from apache_polaris.sdk.catalog.models.create_policy_request import
CreatePolicyRequest
61d71
< from apache_polaris.sdk.catalog.models.detach_policy_request import
DetachPolicyRequest
74,75d83
< from apache_polaris.sdk.catalog.models.generic_table import GenericTable
< from apache_polaris.sdk.catalog.models.get_applicable_policies_response
import GetApplicablePoliciesResponse
78,79d85
< from apache_polaris.sdk.catalog.models.iceberg_error_response1 import
IcebergErrorResponse1
< from apache_polaris.sdk.catalog.models.list_generic_tables_response import
ListGenericTablesResponse
81d86
< from apache_polaris.sdk.catalog.models.list_policies_response import
ListPoliciesResponse
86,87d90
< from apache_polaris.sdk.catalog.models.load_generic_table_response import
LoadGenericTableResponse
< from apache_polaris.sdk.catalog.models.load_policy_response import
LoadPolicyResponse
95,96d97
< from apache_polaris.sdk.catalog.models.notification_request import
NotificationRequest
< from apache_polaris.sdk.catalog.models.notification_type import
NotificationType
106,108d106
< from apache_polaris.sdk.catalog.models.policy import Policy
< from apache_polaris.sdk.catalog.models.policy_attachment_target import
PolicyAttachmentTarget
< from apache_polaris.sdk.catalog.models.policy_identifier import
PolicyIdentifier
121a120
> from apache_polaris.sdk.catalog.models.sql_view_representation import
SQLViewRepresentation
141d139
< from apache_polaris.sdk.catalog.models.sql_view_representation import
SQLViewRepresentation
150d147
< from apache_polaris.sdk.catalog.models.table_update_notification import
TableUpdateNotification
160d156
< from apache_polaris.sdk.catalog.models.update_policy_request import
UpdatePolicyRequest
165,166d160
< from apache_polaris.sdk.catalog.models.view_representation import
ViewRepresentation
< from apache_polaris.sdk.catalog.models.view_requirement import
ViewRequirement
168c162,163
< from apache_polaris.sdk.catalog.models.view_version import ViewVersion
\ No newline at end of file
---
> from apache_polaris.sdk.catalog.models.view_version import ViewVersion
>
```
--
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]