fix: handle missing createdAt/updatedAt keys and support snake_case from backend#43
Open
lexDiller wants to merge 1 commit intoInfisical:mainfrom
Open
fix: handle missing createdAt/updatedAt keys and support snake_case from backend#43lexDiller wants to merge 1 commit intoInfisical:mainfrom
lexDiller wants to merge 1 commit intoInfisical:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi there!
I used the methods listed in the docs to import secrets from infisical via the SDK, but I ran into a problem:
Traceback (most recent call last):
File "/app/src/redis_worker/worker.py", line 10, in
from config.secrets_config import get_secret
File "/app/src/config/secrets_config.py", line 28, in
raw = client.secrets.list_secrets(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/infisical_sdk/resources/secrets.py", line 52, in list_secrets
result = self.requests.get(
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/infisical_sdk/infisical_requests.py", line 88, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/infisical_sdk/infisical_requests.py", line 169, in get
parsed_data = model.from_dict(data) if hasattr(model, 'from_dict') else data
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/infisical_sdk/api_types.py", line 105, in from_dict
secrets=[BaseSecret.from_dict(secret) for secret in data['secrets']],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/infisical_sdk/api_types.py", line 40, in from_dict
return cls(**filtered_data)
^^^^^^^^^^^^^^^^^^^^
TypeError: BaseSecret.init() missing 2 required positional arguments: 'createdAt' and 'updatedAt'.
So what was done:
Made the
createdateandupdatedatefields optionalIn the
BazasecretandKmsKeymodels, these fields are now of typeOptional[str] = None, meaning they may be missing (there will beNone).Added processing of different field names ('snake_case' → `camelCase')
The
from_dictmethod of the base model now includes shifting values from thecreated_atfields. =created Atandupdated_at=updatedAtsnake_case(for example,created_at), the data will be converted tocamelCaseinside the model, and the constructor will not crash even if the API returns one of two options.