You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Taragolis (via GitHub)" <gi...@apache.org> on 2024/02/04 11:42:52 UTC

[PR] Use generic utils for cleanup db and operate with temp objects in TestXcomObjectStoreBackend [airflow]

Taragolis opened a new pull request, #37166:
URL: https://github.com/apache/airflow/pull/37166

   <!--
    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/
   -->
   
   Use pytest temporary directory structure instead of hardcoded `/tmp/xcom`
   Use `tests.test_utils.db` for cleanup test DB.
   Avoid to directly change configuration, instead of that use `conf_vars` fixture
   
   <!-- 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 [newsfragments](https://github.com/apache/airflow/tree/main/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] Use generic utils for cleanup db and operate with temp objects in TestXcomObjectStoreBackend [airflow]

Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #37166:
URL: https://github.com/apache/airflow/pull/37166#discussion_r1477295533


##########
tests/providers/common/io/xcom/test_backend.py:
##########
@@ -86,28 +87,19 @@ def task_instance(task_instance_factory):
 
 
 class TestXcomObjectStoreBackend:
-    path = "file:/tmp/xcom"
-
-    def setup_method(self):
-        try:
-            conf.add_section("common.io")
-        except DuplicateSectionError:
-            pass
-        conf.set("core", "xcom_backend", "airflow.providers.common.io.xcom.backend.XComObjectStoreBackend")
-        conf.set("common.io", "xcom_objectstore_path", self.path)
-        conf.set("common.io", "xcom_objectstore_threshold", "50")
-        settings.configure_vars()
-
-    def teardown_method(self):
-        conf.remove_option("core", "xcom_backend")
-        conf.remove_option("common.io", "xcom_objectstore_path")
-        conf.remove_option("common.io", "xcom_objectstore_threshold")
-        settings.configure_vars()
-        p = ObjectStoragePath(self.path)
-        if p.exists():
-            p.rmdir(recursive=True)
-
-    @pytest.mark.db_test
+    @pytest.fixture(autouse=True)
+    def setup_test_cases(self, tmp_path):
+        xcom_path = tmp_path / "xcom"
+        xcom_path.mkdir()
+        self.path = f"file:{xcom_path}"

Review Comment:
   @bolkedebruin I'm not sure is it a bug or is it by design
   
   When `[common.io] xcom_objectstore_path` set to **file:/foo/bar** XComBackend use absolute path `/foo/bar`
   When `[common.io] xcom_objectstore_path` set to **file://foo/bar** XComBackend use relative to the current directory path `foo/bar`
   When `[common.io] xcom_objectstore_path` set to **file:///foo/bar** XComBackend failed with an error `ValueError: Invalid key`



-- 
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] Use generic utils for cleanup db and operate with temp objects in TestXcomObjectStoreBackend [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #37166:
URL: https://github.com/apache/airflow/pull/37166#discussion_r1535741587


##########
tests/providers/common/io/xcom/test_backend.py:
##########
@@ -86,28 +87,19 @@ def task_instance(task_instance_factory):
 
 
 class TestXcomObjectStoreBackend:
-    path = "file:/tmp/xcom"
-
-    def setup_method(self):
-        try:
-            conf.add_section("common.io")
-        except DuplicateSectionError:
-            pass
-        conf.set("core", "xcom_backend", "airflow.providers.common.io.xcom.backend.XComObjectStoreBackend")
-        conf.set("common.io", "xcom_objectstore_path", self.path)
-        conf.set("common.io", "xcom_objectstore_threshold", "50")
-        settings.configure_vars()
-
-    def teardown_method(self):
-        conf.remove_option("core", "xcom_backend")
-        conf.remove_option("common.io", "xcom_objectstore_path")
-        conf.remove_option("common.io", "xcom_objectstore_threshold")
-        settings.configure_vars()
-        p = ObjectStoragePath(self.path)
-        if p.exists():
-            p.rmdir(recursive=True)
-
-    @pytest.mark.db_test
+    @pytest.fixture(autouse=True)
+    def setup_test_cases(self, tmp_path):
+        xcom_path = tmp_path / "xcom"
+        xcom_path.mkdir()
+        self.path = f"file:{xcom_path}"

Review Comment:
   IMHO
   
   > 1) When [common.io] xcom_objectstore_path set to file:/foo/bar XComBackend use absolute path /foo/bar
   > 2) When [common.io] xcom_objectstore_path set to file://foo/bar XComBackend use relative to the current directory path foo/bar
   > 3) When [common.io] xcom_objectstore_path set to file:///foo/bar XComBackend failed with an error ValueError: Invalid key
   
   1) 2) are ok. 1) is perfectly fine according to RFC3986 and explained nicely here https://en.wikipedia.org/wiki/File_URI_scheme 2) is not correct (`://` should be followed by eiter '/' or literal localhost,) but many implementation accept it as a shortcut
   
   3) invalid key should be accepted - it's fully valid according to RFC and many implementations and should be `/foo/bar` absolute).
   
   But maybe it's been fixed in the last iteration already ?
   



-- 
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] Use generic utils for cleanup db and operate with temp objects in TestXcomObjectStoreBackend [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #37166:
URL: https://github.com/apache/airflow/pull/37166#issuecomment-2014085720

   This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.


-- 
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] Use generic utils for cleanup db and operate with temp objects in TestXcomObjectStoreBackend [airflow]

Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #37166:
URL: https://github.com/apache/airflow/pull/37166#discussion_r1544845557


##########
tests/providers/common/io/xcom/test_backend.py:
##########
@@ -86,28 +87,19 @@ def task_instance(task_instance_factory):
 
 
 class TestXcomObjectStoreBackend:
-    path = "file:/tmp/xcom"
-
-    def setup_method(self):
-        try:
-            conf.add_section("common.io")
-        except DuplicateSectionError:
-            pass
-        conf.set("core", "xcom_backend", "airflow.providers.common.io.xcom.backend.XComObjectStoreBackend")
-        conf.set("common.io", "xcom_objectstore_path", self.path)
-        conf.set("common.io", "xcom_objectstore_threshold", "50")
-        settings.configure_vars()
-
-    def teardown_method(self):
-        conf.remove_option("core", "xcom_backend")
-        conf.remove_option("common.io", "xcom_objectstore_path")
-        conf.remove_option("common.io", "xcom_objectstore_threshold")
-        settings.configure_vars()
-        p = ObjectStoragePath(self.path)
-        if p.exists():
-            p.rmdir(recursive=True)
-
-    @pytest.mark.db_test
+    @pytest.fixture(autouse=True)
+    def setup_test_cases(self, tmp_path):
+        xcom_path = tmp_path / "xcom"
+        xcom_path.mkdir()
+        self.path = f"file:{xcom_path}"

Review Comment:
   More common URI `file:///foo/bar` seems like now worked fine



-- 
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] Use generic utils for cleanup db and operate with temp objects in TestXcomObjectStoreBackend [airflow]

Posted by "bolkedebruin (via GitHub)" <gi...@apache.org>.
bolkedebruin commented on code in PR #37166:
URL: https://github.com/apache/airflow/pull/37166#discussion_r1477430920


##########
tests/providers/common/io/xcom/test_backend.py:
##########
@@ -86,28 +87,19 @@ def task_instance(task_instance_factory):
 
 
 class TestXcomObjectStoreBackend:
-    path = "file:/tmp/xcom"
-
-    def setup_method(self):
-        try:
-            conf.add_section("common.io")
-        except DuplicateSectionError:
-            pass
-        conf.set("core", "xcom_backend", "airflow.providers.common.io.xcom.backend.XComObjectStoreBackend")
-        conf.set("common.io", "xcom_objectstore_path", self.path)
-        conf.set("common.io", "xcom_objectstore_threshold", "50")
-        settings.configure_vars()
-
-    def teardown_method(self):
-        conf.remove_option("core", "xcom_backend")
-        conf.remove_option("common.io", "xcom_objectstore_path")
-        conf.remove_option("common.io", "xcom_objectstore_threshold")
-        settings.configure_vars()
-        p = ObjectStoragePath(self.path)
-        if p.exists():
-            p.rmdir(recursive=True)
-
-    @pytest.mark.db_test
+    @pytest.fixture(autouse=True)
+    def setup_test_cases(self, tmp_path):
+        xcom_path = tmp_path / "xcom"
+        xcom_path.mkdir()
+        self.path = f"file:{xcom_path}"

Review Comment:
   I *think* that is expected behavior but I need to check. 



-- 
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] Use generic utils for cleanup db and operate with temp objects in TestXcomObjectStoreBackend [airflow]

Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on PR #37166:
URL: https://github.com/apache/airflow/pull/37166#issuecomment-2027724000

   This PR better merge (and possibly rebase) after https://github.com/apache/airflow/pull/38608


-- 
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] Use generic utils for cleanup db and operate with temp objects in TestXcomObjectStoreBackend [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #37166:
URL: https://github.com/apache/airflow/pull/37166


-- 
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] Use generic utils for cleanup db and operate with temp objects in TestXcomObjectStoreBackend [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on PR #37166:
URL: https://github.com/apache/airflow/pull/37166#issuecomment-2028987177

   Turns out this got merged first so I rebased #38608 instead. I think I did it right? @Taragolis 


-- 
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