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 4677ef995..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,8 +12,9 @@ Timestamp, Timestamptz, ) +from piccolo.querystring import QueryString 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,12 +43,18 @@ def setUp(self): def tearDown(self): MyTable.alter().drop_table().run_sync() - @engines_only("postgres", "sqlite") + @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,12 +63,19 @@ def test_storage(self): assert row is not None self.assertEqual(row.value, [1, 2, 3]) - @engines_only("postgres") + @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,66 +84,92 @@ def test_index(self): MyTable.select(MyTable.value[0]).first().run_sync(), {"value": 1} ) - @engines_only("postgres") + @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_only("postgres") + @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_only("postgres") + @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() @@ -137,7 +179,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 +190,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 +201,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