@@ -219,20 +219,25 @@ def __str__(self):
219
219
"orm models. {} (registered for {}) doesn't fit the bill." \
220
220
.format (self .args [0 ].__name__ , self .args [1 ])
221
221
222
+ class NoTypeSpecified (Exception ):
223
+ def __str__ (self ):
224
+ return "You tried to register {} as an orm model, but it has no " \
225
+ "typname attribute." .format (self .args [0 ].__name__ )
226
+
222
227
class NoSuchType (Exception ):
223
228
def __str__ (self ):
224
- return "You tried to register an orm Model for typname {}, but no " \
229
+ return "You tried to register an orm model for typname {}, but no " \
225
230
"such type exists in the pg_type table of your database." \
226
231
.format (self .args [0 ])
227
232
228
233
class AlreadyRegistered (Exception ):
229
234
def __str__ (self ):
230
- return "The Model {} is already registered for the typname {}." \
235
+ return "The model {} is already registered for the typname {}." \
231
236
.format (self .args [0 ].__name__ , self .args [1 ])
232
237
233
238
class NotRegistered (Exception ):
234
239
def __str__ (self ):
235
- return "The Model {} is not registered." .format (self .args [0 ].__name__ )
240
+ return "The model {} is not registered." .format (self .args [0 ].__name__ )
236
241
237
242
238
243
# The Main Event
@@ -460,7 +465,9 @@ def register_model(self, ModelSubclass):
460
465
461
466
:param ModelSubclass: the :py:class:`~postgres.orm.Model` subclass to
462
467
register with this :py:class:`~postgres.Postgres` instance
463
- :raises: :py:exc:`~postgres.NotAModel`, :py:exc:`~postgres.NoSuchType`,
468
+ :raises: :py:exc:`~postgres.NotAModel`,
469
+ :py:exc:`~postgres.NoTypeSpecified`,
470
+ :py:exc:`~postgres.NoSuchType`,
464
471
:py:exc:`~postgres.AlreadyRegistered`
465
472
466
473
.. note::
@@ -472,6 +479,9 @@ def register_model(self, ModelSubclass):
472
479
if not issubclass (ModelSubclass , Model ):
473
480
raise NotAModel (ModelSubclass )
474
481
482
+ if getattr (ModelSubclass , 'typname' , None ) is None :
483
+ raise NoTypeSpecified (ModelSubclass )
484
+
475
485
n = self .one_or_zero ( "SELECT count(*) FROM pg_type WHERE typname=%s"
476
486
, (ModelSubclass .typname ,)
477
487
)
0 commit comments