]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
including enum name in error message
authorRamonWill <ramonwilliams@hotmail.co.uk>
Mon, 3 Aug 2020 17:43:43 +0000 (18:43 +0100)
committerRamonWill <ramonwilliams@hotmail.co.uk>
Mon, 3 Aug 2020 17:43:43 +0000 (18:43 +0100)
lib/sqlalchemy/sql/sqltypes.py
test/sql/test_types.py

index 52d80da669b69cfaee599652143e6086221a27b7..0b03dafae3864d567cd9442caf2e6991d9717a87 100644 (file)
@@ -1557,8 +1557,12 @@ class Enum(Emulated, String, SchemaType):
                 util.raise_(
                     LookupError(
                         "'%s' is not among the defined enum values. "
-                        "Possible values: %s"
-                        % (elem, langhelpers._repr_tuple_names(self.enums))
+                        "Enum name: %s. Possible values: %s"
+                        % (
+                            elem,
+                            self.name,
+                            langhelpers._repr_tuple_names(self.enums),
+                        )
                     ),
                     replace_context=err,
                 )
@@ -1583,8 +1587,12 @@ class Enum(Emulated, String, SchemaType):
             util.raise_(
                 LookupError(
                     "'%s' is not among the defined enum values. "
-                    "Possible values: %s"
-                    % (elem, langhelpers._repr_tuple_names(self.enums))
+                    "Enum name: %s. Possible values: %s"
+                    % (
+                        elem,
+                        self.name,
+                        langhelpers._repr_tuple_names(self.enums),
+                    )
                 ),
                 replace_context=err,
             )
index dfbb78245ace24a8d83398fcd57511609b58efe3..30309046e9ed797701b227cd39db3a4cb331538c 100644 (file)
@@ -1452,7 +1452,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
         eq_(bind_processor("foo"), "foo")
         assert_raises_message(
             LookupError,
-            "'5' is not among the defined enum values. "
+            "'5' is not among the defined enum values. Enum name: someenum. "
             "Possible values: one, two, three, ..., BMember",
             bind_processor,
             5,
@@ -1460,7 +1460,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
 
         assert_raises_message(
             LookupError,
-            "'foo' is not among the defined enum values. "
+            "'foo' is not among the defined enum values. Enum name: someenum. "
             "Possible values: one, two, three, ..., BMember",
             bind_processor_validates,
             "foo",
@@ -1471,7 +1471,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
         eq_(result_processor("one"), self.one)
         assert_raises_message(
             LookupError,
-            "'foo' is not among the defined enum values. "
+            "'foo' is not among the defined enum values. Enum name: someenum. "
             "Possible values: one, two, three, ..., BMember",
             result_processor,
             "foo",
@@ -1487,7 +1487,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
 
         assert_raises_message(
             LookupError,
-            "'5' is not among the defined enum values. "
+            "'5' is not among the defined enum values. Enum name: someenum. "
             "Possible values: one, two, three, ..., BMember",
             literal_processor,
             5,
@@ -1495,7 +1495,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
 
         assert_raises_message(
             LookupError,
-            "'foo' is not among the defined enum values. "
+            "'foo' is not among the defined enum values. Enum name: someenum. "
             "Possible values: one, two, three, ..., BMember",
             validate_literal_processor,
             "foo",
@@ -1513,7 +1513,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
         eq_(bind_processor("foo"), "foo")
         assert_raises_message(
             LookupError,
-            "'5' is not among the defined enum values. "
+            "'5' is not among the defined enum values. Enum name: None. "
             "Possible values: one, two",
             bind_processor,
             5,
@@ -1521,7 +1521,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
 
         assert_raises_message(
             LookupError,
-            "'foo' is not among the defined enum values. "
+            "'foo' is not among the defined enum values. Enum name: None. "
             "Possible values: one, two",
             bind_processor_validates,
             "foo",
@@ -1532,7 +1532,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
         eq_(result_processor("one"), "one")
         assert_raises_message(
             LookupError,
-            "'foo' is not among the defined enum values. "
+            "'foo' is not among the defined enum values. Enum name: None. "
             "Possible values: one, two",
             result_processor,
             "foo",
@@ -1546,7 +1546,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
         eq_(literal_processor("foo"), "'foo'")
         assert_raises_message(
             LookupError,
-            "'5' is not among the defined enum values. "
+            "'5' is not among the defined enum values. Enum name: None. "
             "Possible values: one, two",
             literal_processor,
             5,
@@ -1554,7 +1554,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
 
         assert_raises_message(
             LookupError,
-            "'foo' is not among the defined enum values. "
+            "'foo' is not among the defined enum values. Enum name: None. "
             "Possible values: one, two",
             validate_literal_processor,
             "foo",
@@ -1567,7 +1567,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
         eq_(bind_processor("one"), "one")
         assert_raises_message(
             LookupError,
-            "'5' is not among the defined enum values. "
+            "'5' is not among the defined enum values. Enum name: None. "
             "Possible values: one, twothreefou.., seven, eight",
             bind_processor,
             5,
@@ -1579,7 +1579,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
 
         assert_raises_message(
             LookupError,
-            "'5' is not among the defined enum values. "
+            "'5' is not among the defined enum values. Enum name: None. "
             "Possible values: None",
             bind_processor,
             5,
@@ -1781,7 +1781,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
             assert_raises_message(
                 LookupError,
                 "'four' is not among the defined enum values. "
-                "Possible values: one, two, three",
+                "Enum name: None. Possible values: one, two, three",
                 conn.scalar,
                 select([self.tables.non_native_enum_table.c.someotherenum]),
             )