Re: problem with timezone parsing
Karsten Hilbert <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Mar 02, 2009 at 09:31:06AM +0100, Federico Di Gregorio wrote: > in the process of adding your code to extras.py I found some code I > don't understand. > > Il giorno mer, 25/02/2009 alle 14.00 +0100, Karsten Hilbert ha scritto: > > def _convert_ts_with_odd_tz(string_value, cursor): > > try: > > return DATETIME(string_value, cursor) > > except (DataError,), exc: > > if string_value is None: > > raise > > I don't understand how string_value could be None here. If it was None > before then DATETIME would have just returned None. It is safe to remove > it or do you know something that I am missing? That's unlikely :-) However, I have *observed* string_value to be None in the wild, the consequence being that DATETIME threw an exception (on second thought I should have realized that that hints at a deeper problem because, yes, it really ought to return None). So I put in the check such as NOT to retry parsing with a truncated string value. So, all in all, yes, the check should be superfluous -- but it shouldn't hurt. And it protects the pre-parsing stages (the truncation) following it from input it cannot handle. Karsten -- GPG key ID E4071346 @ wwwkeys.pgp.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346