Dev-iL commented on code in PR #58062:
URL: https://github.com/apache/airflow/pull/58062#discussion_r2517648645
##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -372,12 +379,12 @@ def get_extra(self) -> str:
f"Can't decrypt `extra` params for login={self.login}, "
f"FERNET_KEY configuration is missing"
)
- extra_val = fernet.decrypt(bytes(self._extra, "utf-8")).decode()
+ extra_val: str | None = fernet.decrypt(bytes(self._extra,
"utf-8")).decode()
Review Comment:
This is very similar to `get_password`, but without the guards that ensure a
string is returned. Perhaps it's worth introducing a general
decryption+decoding method?
Something like:
```python
def _safe_decrypt(fld: str) -> str:
try:
as_bytes = bytes(self._extra, "utf-8")
except SomeBytesConversionError:
as_bytes = fld
try:
decrypted = fernet.decrypt(as_bytes)
except SomeDecryptionError:
decrypted = as_bytes
try:
decoded = decrypted.decode()
except SomeDecodingError:
decoded = decrypted
return decoded
```
##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -348,7 +348,14 @@ def get_password(self) -> str | None:
f"Can't decrypt encrypted password for login={self.login}
"
f"FERNET_KEY configuration is missing"
)
- return fernet.decrypt(bytes(self._password, "utf-8")).decode()
+ try:
+ return fernet.decrypt(bytes(self._password, "utf-8")).decode()
+ except Exception as e:
+ from cryptography.fernet import InvalidToken
+
+ if isinstance(e, InvalidToken):
+ return self._password
+ raise
Review Comment:
I think it can be simplified to
```suggestion
except InvalidToken as e:
return self._password
```
...then it will re-raise automatically if the exception is of a different
type.
##########
airflow-core/src/airflow/models/serialized_dag.py:
##########
@@ -514,7 +514,7 @@ def get_latest_serialized_dags(
)
.where(cls.dag_id.in_(dag_ids))
).all()
- return latest_serdags or []
+ return list(latest_serdags)
Review Comment:
Consider changing the return type of the method to
`Iterable[SerializedDagModel]` instead a potentially unnecessary cast.
--
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]