From d7c931029417575f2b6ba7cd1d174919d64d7f14 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Fri, 7 Jun 2024 21:34:25 +0100 Subject: [PATCH 1/2] start refactoring array tests, so they work with CockroachDB --- tests/columns/test_array.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/columns/test_array.py b/tests/columns/test_array.py index 4677ef995..7da4dadfb 100644 --- a/tests/columns/test_array.py +++ b/tests/columns/test_array.py @@ -11,7 +11,7 @@ Timestamptz, ) from piccolo.table import Table -from tests.base import engines_only, sqlite_only +from tests.base import engines_only, engines_skip, sqlite_only class MyTable(Table): @@ -40,7 +40,6 @@ def setUp(self): def tearDown(self): MyTable.alter().drop_table().run_sync() - @engines_only("postgres", "sqlite") def test_storage(self): """ Make sure data can be stored and retrieved. @@ -54,7 +53,7 @@ def test_storage(self): assert row is not None self.assertEqual(row.value, [1, 2, 3]) - @engines_only("postgres") + @engines_skip("sqlite") def test_index(self): """ Indexes should allow individual array elements to be queried. @@ -68,7 +67,7 @@ def test_index(self): MyTable.select(MyTable.value[0]).first().run_sync(), {"value": 1} ) - @engines_only("postgres") + @engines_skip("sqlite") def test_all(self): """ Make sure rows can be retrieved where all items in an array match a @@ -95,7 +94,7 @@ def test_all(self): None, ) - @engines_only("postgres") + @engines_skip("sqlite") def test_any(self): """ Make sure rows can be retrieved where any items in an array match a @@ -122,7 +121,7 @@ def test_any(self): None, ) - @engines_only("postgres") + @engines_skip("sqlite") def test_cat(self): """ Make sure values can be appended to an array. @@ -137,7 +136,8 @@ def test_cat(self): ).run_sync() self.assertEqual( - MyTable.select().run_sync(), [{"id": 1, "value": [1, 1, 1, 2]}] + MyTable.select(MyTable.value).run_sync(), + [{"value": [1, 1, 1, 2]}], ) # Try plus symbol @@ -147,7 +147,8 @@ def test_cat(self): ).run_sync() self.assertEqual( - MyTable.select().run_sync(), [{"id": 1, "value": [1, 1, 1, 2, 3]}] + MyTable.select(MyTable.value).run_sync(), + [{"value": [1, 1, 1, 2, 3]}], ) # Make sure non-list values work @@ -157,8 +158,8 @@ def test_cat(self): ).run_sync() self.assertEqual( - MyTable.select().run_sync(), - [{"id": 1, "value": [1, 1, 1, 2, 3, 4]}], + MyTable.select(MyTable.value).run_sync(), + [{"value": [1, 1, 1, 2, 3, 4]}], ) @sqlite_only From 9a708001029ae098f250b334b73020bfc015e9a7 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Mon, 10 Jun 2024 17:53:20 +0100 Subject: [PATCH 2/2] mark slow array tests --- pyproject.toml | 3 +- scripts/test-cockroach.sh | 2 +- tests/columns/test_array.py | 61 +++++++++++++++++++++++++++++++------ 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ec6a0655e..eed50963a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,8 @@ ignore_missing_imports = true [tool.pytest.ini_options] markers = [ "integration", - "speed" + "speed", + "cockroach_array_slow" ] [tool.coverage.run] diff --git a/scripts/test-cockroach.sh b/scripts/test-cockroach.sh index 1c944aeae..9c8d23ca8 100755 --- a/scripts/test-cockroach.sh +++ b/scripts/test-cockroach.sh @@ -10,5 +10,5 @@ python3 -m pytest \ --cov-report=xml \ --cov-report=html \ --cov-fail-under=80 \ - -m "not integration" \ + -m "not integration and not cockroach_array_slow" \ -s $@ diff --git a/tests/columns/test_array.py b/tests/columns/test_array.py index 7da4dadfb..0b96e176c 100644 --- a/tests/columns/test_array.py +++ b/tests/columns/test_array.py @@ -1,6 +1,8 @@ import datetime from unittest import TestCase +import pytest + from piccolo.columns.column_types import ( Array, BigInt, @@ -10,6 +12,7 @@ Timestamp, Timestamptz, ) +from piccolo.querystring import QueryString from piccolo.table import Table from tests.base import engines_only, engines_skip, sqlite_only @@ -40,11 +43,18 @@ def setUp(self): def tearDown(self): MyTable.alter().drop_table().run_sync() + @pytest.mark.cockroach_array_slow def test_storage(self): """ Make sure data can be stored and retrieved. - 🐛 Cockroach bug: https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg + In CockroachDB <= v22.2.0 we had this error: + + * https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg + + In newer CockroachDB versions, it runs but is very slow: + + * https://github.com/piccolo-orm/piccolo/issues/1005 """ # noqa: E501 MyTable(value=[1, 2, 3]).save().run_sync() @@ -54,11 +64,18 @@ def test_storage(self): self.assertEqual(row.value, [1, 2, 3]) @engines_skip("sqlite") + @pytest.mark.cockroach_array_slow def test_index(self): """ Indexes should allow individual array elements to be queried. - 🐛 Cockroach bug: https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg + In CockroachDB <= v22.2.0 we had this error: + + * https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg + + In newer CockroachDB versions, it runs but is very slow: + + * https://github.com/piccolo-orm/piccolo/issues/1005 """ # noqa: E501 MyTable(value=[1, 2, 3]).save().run_sync() @@ -68,65 +85,91 @@ def test_index(self): ) @engines_skip("sqlite") + @pytest.mark.cockroach_array_slow def test_all(self): """ Make sure rows can be retrieved where all items in an array match a given value. - 🐛 Cockroach bug: https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg + In CockroachDB <= v22.2.0 we had this error: + + * https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg + + In newer CockroachDB versions, it runs but is very slow: + + * https://github.com/piccolo-orm/piccolo/issues/1005 """ # noqa: E501 MyTable(value=[1, 1, 1]).save().run_sync() + # We have to explicitly specify the type, so CockroachDB works. self.assertEqual( MyTable.select(MyTable.value) - .where(MyTable.value.all(1)) + .where(MyTable.value.all(QueryString("{}::INTEGER", 1))) .first() .run_sync(), {"value": [1, 1, 1]}, ) + # We have to explicitly specify the type, so CockroachDB works. self.assertEqual( MyTable.select(MyTable.value) - .where(MyTable.value.all(0)) + .where(MyTable.value.all(QueryString("{}::INTEGER", 0))) .first() .run_sync(), None, ) @engines_skip("sqlite") + @pytest.mark.cockroach_array_slow def test_any(self): """ Make sure rows can be retrieved where any items in an array match a given value. - 🐛 Cockroach bug: https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg + In CockroachDB <= v22.2.0 we had this error: + + * https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg + + In newer CockroachDB versions, it runs but is very slow: + + * https://github.com/piccolo-orm/piccolo/issues/1005 """ # noqa: E501 + MyTable(value=[1, 2, 3]).save().run_sync() + # We have to explicitly specify the type, so CockroachDB works. self.assertEqual( MyTable.select(MyTable.value) - .where(MyTable.value.any(1)) + .where(MyTable.value.any(QueryString("{}::INTEGER", 1))) .first() .run_sync(), {"value": [1, 2, 3]}, ) + # We have to explicitly specify the type, so CockroachDB works. self.assertEqual( MyTable.select(MyTable.value) - .where(MyTable.value.any(0)) + .where(MyTable.value.any(QueryString("{}::INTEGER", 0))) .first() .run_sync(), None, ) @engines_skip("sqlite") + @pytest.mark.cockroach_array_slow def test_cat(self): """ Make sure values can be appended to an array. - 🐛 Cockroach bug: https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg + In CockroachDB <= v22.2.0 we had this error: + + * https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg + + In newer CockroachDB versions, it runs but is very slow: + + * https://github.com/piccolo-orm/piccolo/issues/1005 """ # noqa: E501 MyTable(value=[1, 1, 1]).save().run_sync()