diff options
author | Jonathan Ellis <jbellis@gmail.com> | 2006-10-04 22:03:15 +0000 |
---|---|---|
committer | Jonathan Ellis <jbellis@gmail.com> | 2006-10-04 22:03:15 +0000 |
commit | f61cd50128cd5b1f996c68927b0af6ed9e434ea4 (patch) | |
tree | 7b8b3baa6e9522f0a696bbd7bc3cbec69283221e /lib/sqlalchemy/ext/sqlsoup.py | |
parent | 2eac1481f329e4226defde54973ba02d06df5b46 (diff) | |
download | sqlalchemy-f61cd50128cd5b1f996c68927b0af6ed9e434ea4.tar.gz |
r/m sqlsoup.NoSuchTableError (SA proper takes care of that now)
add sqlsoup.PKNotFoundError
Diffstat (limited to 'lib/sqlalchemy/ext/sqlsoup.py')
-rw-r--r-- | lib/sqlalchemy/ext/sqlsoup.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/sqlalchemy/ext/sqlsoup.py b/lib/sqlalchemy/ext/sqlsoup.py index a0c8bd351..b8aaf2fa5 100644 --- a/lib/sqlalchemy/ext/sqlsoup.py +++ b/lib/sqlalchemy/ext/sqlsoup.py @@ -153,6 +153,16 @@ Boring tests here. Nothing of real expository value. >>> db.users.select(db.users.c.classname==None, order_by=[db.users.c.name]) [MappedUsers(name='Bhargan Basepair',email='basepair+nospam@example.edu',password='basepair',classname=None,admin=1), MappedUsers(name='Joe Student',email='student@example.edu',password='student',classname=None,admin=0)] + + >>> db.nopk + Traceback (most recent call last): + ... + PKNotFoundError: table 'nopk' does not have a primary key defined + + >>> db.nosuchtable + Traceback (most recent call last): + ... + NoSuchTableError: nosuchtable """ from sqlalchemy import * @@ -200,9 +210,13 @@ values ( (select name from users where name like 'Joe%'), '2006-07-12 0:0:0') ; + +CREATE TABLE nopk ( + i int +); """.split(';') -__all__ = ['NoSuchTableError', 'SqlSoup'] +__all__ = ['PKNotFoundError', 'SqlSoup'] # # thread local SessionContext @@ -215,7 +229,7 @@ class Objectstore(SessionContext): objectstore = Objectstore(create_session) -class NoSuchTableError(SQLAlchemyError): pass +class PKNotFoundError(SQLAlchemyError): pass # metaclass is necessary to expose class methods with getattr, e.g. # we want to pass db.users.select through to users._mapper.select @@ -332,13 +346,13 @@ class SqlSoup: t = self._cache[attr] except KeyError: table = Table(attr, self._metadata, autoload=True, schema=self.schema) + if not table.primary_key.columns: + raise PKNotFoundError('table %r does not have a primary key defined' % attr) if table.columns: t = class_for_table(table) else: t = None self._cache[attr] = t - if not t: - raise NoSuchTableError('%s does not exist' % attr) return t if __name__ == '__main__': |