- changed milestone to 0.7.xx
Python callable column default does not reflect, not documented
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)
-
repo owner -
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.
-
repo owner we've had some developer discussion and will probably use that paragraph or similar, probably at the end of the first part of http://www.sqlalchemy.org/docs/core/schema.html#metadata-reflection - that works ?
-
Account Deleted That works, it would be nice to have a reference or footnote here as well: http://www.sqlalchemy.org/docs/core/schema.html#metadata-defaults
-
repo owner - changed milestone to 0.8.xx
-
repo owner - changed status to resolved
add a new section "limitations of reflection" including this and other potential issues.
-
repo owner - removed milestone
Removing milestone: 0.8.xx (automated comment)
- Log in to comment
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 ?