You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "RoyLee1224 (via GitHub)" <gi...@apache.org> on 2025/10/27 20:32:44 UTC
[PR] Fix MyPy type errors in errors.py & connection.py [airflow]
RoyLee1224 opened a new pull request, #57373:
URL: https://github.com/apache/airflow/pull/57373
## Related issue
part of #56735
## remaining errors in `airflow-core/src/airflow/models/`
- [ ] hitl.py (3 errors)
- [ ] hitl_history.py (3 errors)
- [ ] deadline.py (4 errors)
- [ ] backfill.py (1 error)
- [ ] pool.py (1 error)
- [ ] dagbag.py (2 errors)
- [ ] trigger.py (4 errors)
- [ ] dagrun.py (18 errors)
- [ ] variable.py (4 errors)
- [ ] errors.py (2 errors)
- [ ] connection.py (3 errors)
- [ ] taskmap.py (3 errors) #57324
- [ ] serialized_dag.py (4 errors) #57324
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #57373:
URL: https://github.com/apache/airflow/pull/57373#discussion_r2478409737
##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -128,8 +128,8 @@ class Connection(Base, LoggingMixin):
__tablename__ = "connection"
id: Mapped[int] = mapped_column(Integer(), primary_key=True)
- conn_id: Mapped[str] = mapped_column(String(ID_LEN), unique=True, nullable=False)
- conn_type: Mapped[str] = mapped_column(String(500), nullable=False)
+ conn_id: Mapped[str | None] = mapped_column(String(ID_LEN), unique=True, nullable=False)
+ conn_type: Mapped[str | None] = mapped_column(String(500), nullable=False)
Review Comment:
Those are not consistent. Should they be nullable? If yes then the type should be `str | None` and `nullable=True`, if not it should be `str` and `nullable=False`
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #57373:
URL: https://github.com/apache/airflow/pull/57373#issuecomment-3474081719
Changes look good but yes indeed so many tests are failing now. Maybe the `monkeypatch` is a good solution? But that also makes it harder to review tests, you never know where these automatic values are coming from
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "RoyLee1224 (via GitHub)" <gi...@apache.org>.
RoyLee1224 commented on PR #57373:
URL: https://github.com/apache/airflow/pull/57373#issuecomment-3470797998
Perhaps I should try to use a pytest `monkeypatch` fixture in a central `conftest.py` file, automatically provide default values (e.g., `conn_id="test_dummy_conn"`) to `Connection.__init__` only during the test suite.
I believe this approach has two benefits:
- It keeps this PR small and focused on the MyPy fix.
- It avoids touching 200+ unrelated test files.
What are your thoughts on this approach?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "RoyLee1224 (via GitHub)" <gi...@apache.org>.
RoyLee1224 commented on code in PR #57373:
URL: https://github.com/apache/airflow/pull/57373#discussion_r2479542669
##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -128,8 +128,8 @@ class Connection(Base, LoggingMixin):
__tablename__ = "connection"
id: Mapped[int] = mapped_column(Integer(), primary_key=True)
- conn_id: Mapped[str] = mapped_column(String(ID_LEN), unique=True, nullable=False)
- conn_type: Mapped[str] = mapped_column(String(500), nullable=False)
+ conn_id: Mapped[str | None] = mapped_column(String(ID_LEN), unique=True, nullable=False)
+ conn_type: Mapped[str | None] = mapped_column(String(500), nullable=False)
Review Comment:
Makes sense, I'll add runtime validation in __init__ and fix the unit tests.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #57373:
URL: https://github.com/apache/airflow/pull/57373#discussion_r2469657461
##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -158,7 +158,7 @@ def __init__(
team_id: str | None = None,
):
super().__init__()
- self.conn_id = sanitize_conn_id(conn_id)
+ self.conn_id = sanitize_conn_id(conn_id) # type: ignore[assignment]
Review Comment:
We should try ti solve it instead of ignoring it
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck merged PR #57373:
URL: https://github.com/apache/airflow/pull/57373
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "RoyLee1224 (via GitHub)" <gi...@apache.org>.
RoyLee1224 commented on PR #57373:
URL: https://github.com/apache/airflow/pull/57373#issuecomment-3470441733
### Update
Hi, @vincbeck
I've pushed the changes we discussed. Here’s the summary:
- Changed the `conn_id` and `conn_type` type annotations to `Mapped[str]` to match the `nullable=False` constraint
- Added validation in `Connection.__init__`:
- It now allows `conn_id` to be `None` only for URI-based connections (used`type: ignore` just for that specific path).
- Fixed 17 test files by providing the required `conn_id` and `conn_type` parameters.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "RoyLee1224 (via GitHub)" <gi...@apache.org>.
RoyLee1224 commented on code in PR #57373:
URL: https://github.com/apache/airflow/pull/57373#discussion_r2479542669
##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -128,8 +128,8 @@ class Connection(Base, LoggingMixin):
__tablename__ = "connection"
id: Mapped[int] = mapped_column(Integer(), primary_key=True)
- conn_id: Mapped[str] = mapped_column(String(ID_LEN), unique=True, nullable=False)
- conn_type: Mapped[str] = mapped_column(String(500), nullable=False)
+ conn_id: Mapped[str | None] = mapped_column(String(ID_LEN), unique=True, nullable=False)
+ conn_type: Mapped[str | None] = mapped_column(String(500), nullable=False)
Review Comment:
Sure, I'll add runtime validation in __init__ and fix the unit tests.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "RoyLee1224 (via GitHub)" <gi...@apache.org>.
RoyLee1224 commented on PR #57373:
URL: https://github.com/apache/airflow/pull/57373#issuecomment-3470721442
I found that over 200 tests are now failing because they all mock Connection() without providing a `conn_id`.
I can go through and manually fix all 200+ test files by adding a dummy `conn_id` and `conn_type` to each call, but this will make the PR massive.
I wanted to check if this is this the correct approach?
Or is there a more central/smarter way to handle this?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "RoyLee1224 (via GitHub)" <gi...@apache.org>.
RoyLee1224 commented on code in PR #57373:
URL: https://github.com/apache/airflow/pull/57373#discussion_r2469669700
##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -158,7 +158,7 @@ def __init__(
team_id: str | None = None,
):
super().__init__()
- self.conn_id = sanitize_conn_id(conn_id)
+ self.conn_id = sanitize_conn_id(conn_id) # type: ignore[assignment]
Review Comment:
Sure, I'm on it
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #57373:
URL: https://github.com/apache/airflow/pull/57373#issuecomment-3472945875
Why do yo want to add a runtime validation? Ideally here we do not want to modify any logic but just fix the types. I no longer see the changes in model. Please do not make any modifications in tests
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MyPy type errors in models/errors.py & connection.py [airflow]
Posted by "RoyLee1224 (via GitHub)" <gi...@apache.org>.
RoyLee1224 commented on PR #57373:
URL: https://github.com/apache/airflow/pull/57373#issuecomment-3477446410
Apologies for the confusion earlier. I found a much simpler solution, and the "200+ failing tests" problem is resolved.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org