I've come up with one more obstacle to setting up a project with
authentication when Oracle is the back-end.

model/auth.py sets up classes Group, User, and Permission with
autoincrement=true primary keys, like:
    group_id = Column(Integer, autoincrement=True, primary_key=True)

Under Oracle, however, SQLAlchemy ignores the "autoincrement" keyword:
see 
http://www.sqlalchemy.org/docs/05/reference/dialects/oracle.html#auto-increment-behavior
.  Because of this, the primary key columns get no defaults, and
paster setup-app will fail against Oracle, complaining that NULLs
can't be primary keys.

Two changes fix this:

1. Replacing the autoincrement keywords, as suggested

    group_id = Column(Integer, Sequence('tg_group_id_seq'),
primary_key=True)
    user_id = Column(Integer, Sequence('tg_user_id_seq'),
primary_key=True)
    permission_id = Column(Integer, Sequence('tg_permission_id_seq'),
primary_key=True)

2. Creating the Sequence objects doesn't actually create the sequences
in Oracle.  To do that, I added this to setup_app in websetup.py:

    model.metadata.create_all(bind=config
['pylons.app_globals'].sa_engine) # this was here
    for tbl in model.metadata.tables.values():
        for col in tbl.columns:
            if col.default and isinstance(col.default, Sequence):
                col.default.create(bind=config
['pylons.app_globals'].sa_engine)

After making those changes, I finally got my project setup-app'ed.

Now, having to code these changes in for Oracle projects - how much of
a pain would that be?  And would it make sense to go upstream and ask
about making the changes at the SQLAlchemy level?  I can't think of
any reason why SQLAlchemy itself shouldn't replace an autoincrement
keyword with a Sequence().  Then, my sequence-creating loop may as
well become a part of SQLAlchemy's metadata.create_all() itself - as
far as I can tell.  ( & similar code in a table's .create(), of
course.)  Or am I missing something?

Thanks as always,

--
- Catherine
http://catherinedevlin.blogspot.com/
*** PyOhio * July 25-26, 2009 * pyohio.org ***
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to