Warn when non-datetime timestamps are used in prepared stmts

This commit is contained in:
Tyler Hobbs
2014-01-16 13:37:03 -06:00
parent db11b411f4
commit a8dd5f72c9

View File

@@ -439,6 +439,8 @@ cql_time_formats = (
'%Y-%m-%d'
)
_have_warned_about_timestamps = False
class DateType(_CassandraType):
typename = 'timestamp'
@@ -482,6 +484,20 @@ class DateType(_CassandraType):
if type(v) not in _number_types:
raise TypeError('DateType arguments must be a datetime or timestamp')
if not _have_warned_about_timestamps:
global _have_warned_about_timestamps
_have_warned_about_timestamps = True
warnings.warn("timestamp columns in Cassandra hold a number of "
"milliseconds since the unix epoch. Currently, when executing "
"prepared statements, this driver multiplies timestamp "
"values by 1000 so that the result of time.time() "
"can be used directly. However, the driver cannot "
"match this behavior for non-prepared statements, "
"so the 2.0 version of the driver will no longer multiply "
"timestamps by 1000. It is suggested that you simply use "
"datetime.datetime objects for 'timestamp' values to avoid "
"any ambiguity and to guarantee a smooth upgrade of the "
"driver.")
converted = v * 1e3
return int64_pack(long(converted))