-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metadata: Remove leading underscore #29024
Changes from all commits
cfaf2a4
f7c0e4c
01873dd
e41ab64
bf5e9cd
0685d5f
c439403
e80a3f9
7afe5bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ properties: | |
- githubIssueLabel | ||
- connectorSubtype | ||
- releaseStage | ||
additionalProperties: false | ||
additionalProperties: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we allowing additionalProperties now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it to allow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So Were in a messy middle after discovering the pydantic model generated did not like the leading underscore. The immediate fix(s) we deployed
Now going forward we've got a few metadata files out there that have _ab_internal when they should have ab_internal |
||
properties: | ||
name: | ||
type: string | ||
|
@@ -105,5 +105,5 @@ properties: | |
"$ref": SuggestedStreams.yaml | ||
resourceRequirements: | ||
"$ref": ActorDefinitionResourceRequirements.yaml | ||
_ab_internal: | ||
ab_internal: | ||
"$ref": AirbyteInternal.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import json | ||
from pydantic import BaseModel | ||
|
||
def _apply_default_pydantic_kwargs(kwargs: dict) -> dict: | ||
"""A helper function to apply default kwargs to pydantic models. | ||
|
||
Args: | ||
kwargs (dict): the kwargs to apply | ||
|
||
Returns: | ||
dict: the kwargs with defaults applied | ||
""" | ||
default_kwargs = { | ||
"by_alias": True, # Ensure that the original field name from the jsonschema is used in the event it begins with an underscore (e.g. ab_internal) | ||
"exclude_none": True, # Exclude fields that are None | ||
} | ||
|
||
return {**default_kwargs, **kwargs} | ||
|
||
def to_json_sanitized_dict(pydantic_model_obj: BaseModel, **kwargs) -> dict: | ||
"""A helper function to convert a pydantic model to a sanitized dict. | ||
|
||
Without this pydantic dictionary may contain values that are not JSON serializable. | ||
|
||
Args: | ||
pydantic_model_obj (BaseModel): a pydantic model | ||
|
||
Returns: | ||
dict: a sanitized dictionary | ||
""" | ||
|
||
return json.loads(to_json(pydantic_model_obj, **kwargs)) | ||
|
||
def to_json(pydantic_model_obj: BaseModel, **kwargs) -> str: | ||
"""A helper function to convert a pydantic model to a json string. | ||
|
||
Without this pydantic dictionary may contain values that are not JSON serializable. | ||
|
||
Args: | ||
pydantic_model_obj (BaseModel): a pydantic model | ||
|
||
Returns: | ||
str: a json string | ||
""" | ||
kwargs = _apply_default_pydantic_kwargs(kwargs) | ||
|
||
return pydantic_model_obj.json(**kwargs) | ||
|
||
def to_dict(pydantic_model_obj: BaseModel, **kwargs) -> dict: | ||
"""A helper function to convert a pydantic model to a dict. | ||
|
||
Without this pydantic dictionary may contain values that are not JSON serializable. | ||
|
||
Args: | ||
pydantic_model_obj (BaseModel): a pydantic model | ||
|
||
Returns: | ||
dict: a dict | ||
""" | ||
kwargs = _apply_default_pydantic_kwargs(kwargs) | ||
|
||
return pydantic_model_obj.dict(**kwargs) |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't allowing extra risky? Forbidding extra is a nice way to have consistency guarantees across metadata files