Python callable column default does not reflect, not documented

Issue #2233 resolved
Former user created an issue

When using a python callable as a column default (sqlite backend), the default does not reflect later when the db is loaded.

I am using GUID/UUID pkeys similar to the recipe found here: http://www.sqlalchemy.org/docs/core/types.html#sqlalchemy.types.TypeDecorator

The default ultimately calls uuid.uuid4 (wrapped in TypeDecorator) for the primary key value. If the database is loaded and reflected later the default for the primary key column is lost.

The technical reason for this not reflecting is understandable, this should be considered a documentation bug since this behavior is not warned about.

Comments (7)

  1. Mike Bayer repo owner

    Any suggestions feel free. IMHO this should be clear if one understands the difference between a "server side default" and a "client side default" - the documentation at http://www.sqlalchemy.org/docs/core/schema.html#metadata-defaults calls them "python executed functions". Whereas in Server Side Defaults http://www.sqlalchemy.org/docs/core/schema.html#server-side-defaults it says, specifically, "gets placed in the CREATE TABLE statement ". Not clear enough ?

  2. Former user Account Deleted

    It caught me by surprise initially, although after considering the behind-the-scenes mechanisms it became obvious that these defaults could not be persistent without SQLAlchemy storing internal metadata of some type within the DB (and I know it doesn't currently).

    Assuming you don't want to change the design to accommodate this type of functionality, perhaps something like the following verbage should be added:


    NOTE: Client side defaults (such as python executed functions) are not expressed in the generated CREATE TABLE statement and therefore cannot persist beyond the current SQLA session. Client side defaults will be lost upon table reflection and should be re-created if needed.

  3. Log in to comment