amoghrajesh commented on code in PR #62211:
URL: https://github.com/apache/airflow/pull/62211#discussion_r2844855879
##########
task-sdk/src/airflow/sdk/definitions/connection.py:
##########
@@ -119,9 +120,26 @@ class Connection:
password: str | None = None
port: int | None = None
extra: str | None = None
+ uri: str | None = None
EXTRA_KEY = "__extra__"
+ _URI_FORBIDDEN_FIELDS = ("conn_type", "host", "login", "password",
"schema", "port", "extra")
+
+ def __attrs_post_init__(self) -> None:
+ if self.uri is not None:
+ if any(getattr(self, f) for f in self._URI_FORBIDDEN_FIELDS):
+ raise AirflowException(
+ "You must create an object using the URI or individual
values "
+ "(conn_type, host, login, password, schema, port or
extra). "
+ "You can't mix these two ways to create this object."
+ )
+ conn_from_uri = self.from_uri(self.uri, conn_id=self.conn_id)
+ for attr in attrs.fields(type(conn_from_uri)):
+ if attr.name != "uri":
+ object.__setattr__(self, attr.name, getattr(conn_from_uri,
attr.name))
+ object.__setattr__(self, "uri", None)
Review Comment:
Actually thats a very good idea. Let me try it out.
I went ahead with `__attrs_post_init__` cos I couldn't find any better
alternative at the time and was hesitant with the approach too
--
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]