I am guessing youre using psycopg1. keep in mind I dont have
psycopg1 over here to test with so the code for dates is still just a
guess, although I think it has worked for other people. a patch is
attached and also checked in to rev 1005 that will check for None
first when converting pg1 dates.
Index: lib/sqlalchemy/databases/postgres.py
===================================================================
--- lib/sqlalchemy/databases/postgres.py (revision 1004)
+++ lib/sqlalchemy/databases/postgres.py (revision 1005)
@@ -44,7 +44,10 @@
def convert_bind_param(self, value, engine):
# TODO: perform appropriate postgres1 conversion between Python
DateTime/MXDateTime
# this one doesnt seem to work with the "emulation" mode
- return psycopg.TimestampFromMx(value)
+ if value is not None:
+ return psycopg.TimestampFromMx(value)
+ else:
+ return None
def convert_result_value(self, value, engine):
# TODO: perform appropriate postgres1 conversion between Python
DateTime/MXDateTime
return value
@@ -57,7 +60,10 @@
def convert_bind_param(self, value, engine):
# TODO: perform appropriate postgres1 conversion between Python
DateTime/MXDateTime
# this one doesnt seem to work with the "emulation" mode
- return psycopg.DateFromMx(value)
+ if value is not None:
+ return psycopg.DateFromMx(value)
+ else:
+ return None
def convert_result_value(self, value, engine):
# TODO: perform appropriate postgres1 conversion between Python
DateTime/MXDateTime
return value
@@ -70,7 +76,10 @@
def convert_bind_param(self, value, engine):
# TODO: perform appropriate postgres1 conversion between Python
DateTime/MXDateTime
# this one doesnt seem to work with the "emulation" mode
- return psycopg.TimeFromMx(value)
+ if value is not None:
+ return psycopg.TimeFromMx(value)
+ else:
+ return None
def convert_result_value(self, value, engine):
# TODO: perform appropriate postgres1 conversion between Python
DateTime/MXDateTime
return value
On Feb 19, 2006, at 8:35 PM, marek wrote:
I am trying to use a table with a timestamp in PostgreSQL 8.0.3 with
no success. My definitions are as follows:
CREATE TABLE sessions (
sess_id VARCHAR(128) NOT NULL PRIMARY KEY,
sess_logon TEXT NOT NULL,
sess_ts TIMESTAMP WITH TIME ZONE DEFAULT current_timestamp,
FOREIGN KEY (sess_logon) REFERENCES users (usr_logon) ON DELETE
cascade ON UPDATE cascade,
) WITHOUT OIDS;
sessions = Table('sessions', db,
Column('sess_id', Integer, primary_key=True),
Column('sess_logon', String, ForeignKey('users.usr_logon'),
nullable=False),
Column('sess_ts', DateTime, nullable=True))
Session.mapper = mapper(Session, tables.sessions, properties={
'secret': tables.sessions.c.sess_id,
'logon': tables.sessions.c.sess_logon,
'ts': tables.sessions.c.sess_ts,})
class Session(object):
mapper = None
def __init__(self, secret=None, logon=None, ts=None):
self.secret = secret
self.logon = logon
self.ts = ts
I then run the following code in ipython:
objectstore.begin()
s = Session()
s.secret = 'notsosecret'
s.logon = 'someuser'
objectstore.commit()
The full trace is below, but the error is basically this:
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/databases/
postgres.py
in convert_bind_param(self, value, engine)
TypeError: argument 1 must be DateTime, not None
The behaviour that I wanted to see is that the SA would save the
session and PG would create the timestamp automatically.
What am I doing wrong in terms of using SA?
-marek
----- MORE COMPLETE TRACE ------
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/mapping/
objectstore.py
in commit(*obj)
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/mapping/
objectstore.py
in commit(self, *objects)
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/mapping/
objectstore.py
in execute(self)
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/mapping/
objectstore.py
in execute(self, trans)
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/mapping/mapper.py in
save_obj(self, objects, uow)
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/sql.py in
execute(self, *multiparams, **params)
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/sql.py in
execute(self, *multiparams, **params)
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/engine.py in
execute_compiled(self, compiled, parameters, connection, cursor, echo,
**kwargs)
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/ansisql.py in
get_params(self, **params)
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/sql.py in
typeprocess(self, value, engine)
/home/marek/build/bdist.linux-i686/egg/sqlalchemy/databases/
postgres.py
in convert_bind_param(self, value, engine)
TypeError: argument 1 must be DateTime, not None
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through
log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD
SPLUNK!
http://sel.as-us.falkag.net/sel?
cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users