Skip to content

Commit 6f13d8a

Browse files
asottileharleyk
authored andcommitted
Improve error message where table_name is None (pynamodb#449)
* Improve error message where table_name is None
1 parent 8ab34d0 commit 6f13d8a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pynamodb/models.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,10 +1261,21 @@ def _get_connection(cls):
12611261
"""
12621262
Returns a (cached) connection
12631263
"""
1264-
if not hasattr(cls, "Meta") or cls.Meta.table_name is None:
1264+
if not hasattr(cls, "Meta"):
12651265
raise AttributeError(
1266-
"""As of v1.0 PynamoDB Models require a `Meta` class.
1267-
See https://pynamodb.readthedocs.io/en/latest/release_notes.html"""
1266+
'As of v1.0 PynamoDB Models require a `Meta` class.\n'
1267+
'Model: {0}.{1}\n'
1268+
'See https://pynamodb.readthedocs.io/en/latest/release_notes.html\n'.format(
1269+
cls.__module__, cls.__name__,
1270+
),
1271+
)
1272+
elif not hasattr(cls.Meta, "table_name") or cls.Meta.table_name is None:
1273+
raise AttributeError(
1274+
'As of v1.0 PyanmoDB Models must have a table_name\n'
1275+
'Model: {0}.{1}\n'
1276+
'See https://pynamodb.readthedocs.io/en/latest/release_notes.html'.format(
1277+
cls.__module__, cls.__name__,
1278+
),
12681279
)
12691280
if cls._connection is None:
12701281
cls._connection = TableConnection(cls.Meta.table_name,

0 commit comments

Comments
 (0)