Menu

#100 when using _fromDatabase, column defaults don't work

closed-accepted
Postgres (36)
5
2005-07-20
2005-07-16
No

When using the schema:

create table organization (
orgid SERIAL PRIMARY KEY,
org_name text,
org_long_name text default '',
is_orange bool NOT NULL DEFAULT false,
is_blue bool NOT NULL DEFAULT false,
create_timestamp timestamp DEFAULT now(),
mod_timestamp timestamp,
);

with the code:

class Organization(SQLObject):
_fromDatabase = True
_idName = "orgid"

I found that although no columns are declared 'not null',
the SQLObject constructor insists that most columns are
specified
(producing the error "did not get expected keyword
argument ...")

This is because although it correctly reads the
nullability from the database, it doesn't set the
default value 'None' into the columns it creates if
NULL is allowed for those columns.

Also, default values such as 'false' were not being
interpreted correctly, with the effect that not
specifying these values when creating an Organization
would set such columns to true.

The patch below fixes both of these bugs.

Discussion

  • Jason Hildebrand

    patch to default values when using _fromDatabase

     
  • Oleg Broytman

    Oleg Broytman - 2005-07-20
    • assigned_to: nobody --> phd
    • status: open --> closed-accepted
     
  • Oleg Broytman

    Oleg Broytman - 2005-07-20

    Logged In: YES
    user_id=4799

    The patch is applied at revision 845. Thank you!

     

Log in to post a comment.