Skip to content

Commit

Permalink
Add handler to allow use of internal Pydantic field names.
Browse files Browse the repository at this point in the history
  • Loading branch information
hcpadkins committed Oct 8, 2024
1 parent 3366dae commit a5fbb06
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion grove/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Grove metadata."""

__version__ = "1.5.1"
__version__ = "1.6.0"
__title__ = "grove"
__license__ = "Mozilla Public License 2.0"
__copyright__ = "Copyright 2023 HashiCorp, Inc."
5 changes: 4 additions & 1 deletion grove/connectors/snowflake/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def schema(self) -> Optional[str]:
:return: The "schema" portion of the connector's configuration.
"""
try:
return self.configuration.schema
# The trailing underscore is due to a limitation in Pydantic < 2.0 where
# 'schema' is an internal field. We automatically remap these internal
# fields with a trailing underscore while we migrate to Pydantic >= 2.0
return self.configuration.schema_
except AttributeError:
return "SNOWFLAKE"

Expand Down
13 changes: 13 additions & 0 deletions grove/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ def _decode_fields(cls, values): # noqa: B902
Other encoding schemes may be supported in future, but for now only base64 is
supported.
"""
# This is a horrible hack to allow fields with names that mask Pydantic
# internals. This can be removed once Grove is updated to use Pydantic >= 2.
INTERNAL_FIELDS = ["schema"]

for field in INTERNAL_FIELDS:
value = values.get(field, None)
if value is None:
continue

# Remap the field name to contain a trailing underscore.
values[f"{field}_"] = value
del values[field]

for field, encoding in values.get("encoding", {}).items():
# If the secret is externally stored decoding will be performed after the
# secret has been retrieved. Right now, this field should not exist as it
Expand Down

0 comments on commit a5fbb06

Please sign in to comment.