You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/02/08 23:14:15 UTC
[GitHub] [airflow] pingzh opened a new pull request #21442: Fix Resources __eq__ check
pingzh opened a new pull request #21442:
URL: https://github.com/apache/airflow/pull/21442
it should check if the compared item is the instance of `Resources`
Otherwise, the scheduler won't be able to serialize tasks with `resources` params, due to the following error:

<!--
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 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/
-->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+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 [UPDATING.md](https://github.com/apache/airflow/blob/main/UPDATING.md).
--
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
[GitHub] [airflow] github-actions[bot] commented on pull request #21442: Fix Resources __eq__ check
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #21442:
URL: https://github.com/apache/airflow/pull/21442#issuecomment-1033157805
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.
--
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
[GitHub] [airflow] uranusjr commented on a change in pull request #21442: Fix Resources __eq__ check
Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21442:
URL: https://github.com/apache/airflow/pull/21442#discussion_r803335672
##########
File path: tests/utils/test_operator_resources.py
##########
@@ -0,0 +1,35 @@
+#
+# 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.
+
+import unittest
+
+from airflow.utils.operator_resources import Resources
+
+
+class TestResources(unittest.TestCase):
+ def test_resource_eq(self):
+ r = Resources(**{"cpus": 0.1, "ram": 2048})
+ assert r not in [{}, [], None]
+ assert r == r
+
+ r2 = Resources(**{"cpus": 0.1, "ram": 2048})
+ assert r == r2
+ assert r2 == r
+
+ r3 = Resources(**{"cpus": 0.2, "ram": 2048})
+ assert r != r3
Review comment:
```suggestion
r = Resources(cpus=0.1, ram=2048)
assert r not in [{}, [], None]
assert r == r
r2 = Resources(cpus=0.1, ram=2048)
assert r == r2
assert r2 == r
r3 = Resources(cpus=0.2, ram=2048)
assert r != r3
```
--
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
[GitHub] [airflow] pingzh commented on a change in pull request #21442: Fix Resources __eq__ check
Posted by GitBox <gi...@apache.org>.
pingzh commented on a change in pull request #21442:
URL: https://github.com/apache/airflow/pull/21442#discussion_r803964479
##########
File path: tests/utils/test_operator_resources.py
##########
@@ -0,0 +1,35 @@
+#
+# 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.
+
+import unittest
+
+from airflow.utils.operator_resources import Resources
+
+
+class TestResources(unittest.TestCase):
+ def test_resource_eq(self):
+ r = Resources(**{"cpus": 0.1, "ram": 2048})
+ assert r not in [{}, [], None]
+ assert r == r
+
+ r2 = Resources(**{"cpus": 0.1, "ram": 2048})
+ assert r == r2
+ assert r2 == r
+
+ r3 = Resources(**{"cpus": 0.2, "ram": 2048})
+ assert r != r3
Review comment:
ah, thanks @uranusjr 👍
--
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
[GitHub] [airflow] pingzh commented on a change in pull request #21442: Fix Resources __eq__ check
Posted by GitBox <gi...@apache.org>.
pingzh commented on a change in pull request #21442:
URL: https://github.com/apache/airflow/pull/21442#discussion_r803318460
##########
File path: airflow/utils/operator_resources.py
##########
@@ -50,6 +50,8 @@ def __init__(self, name, units_str, qty):
self._qty = qty
def __eq__(self, other):
+ if not isinstance(other, self.__class__):
+ return False
Review comment:
Great idea. thanks for the comment. updated.
--
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
[GitHub] [airflow] potiuk merged pull request #21442: Fix Resources __eq__ check
Posted by GitBox <gi...@apache.org>.
potiuk merged pull request #21442:
URL: https://github.com/apache/airflow/pull/21442
--
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
[GitHub] [airflow] uranusjr commented on a change in pull request #21442: Fix Resources __eq__ check
Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21442:
URL: https://github.com/apache/airflow/pull/21442#discussion_r803313059
##########
File path: airflow/utils/operator_resources.py
##########
@@ -50,6 +50,8 @@ def __init__(self, name, units_str, qty):
self._qty = qty
def __eq__(self, other):
+ if not isinstance(other, self.__class__):
+ return False
Review comment:
Probably better to use `NotImplemented` instead. https://docs.python.org/3.6/library/constants.html#NotImplemented
--
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