Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105157 > unrolled thread

Is this an error in python-babel or am I missing something?

Started bycl@isbd.net
First post2016-03-17 21:32 +0000
Last post2016-03-18 10:41 +0000
Articles 4 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Is this an error in python-babel or am I missing something? cl@isbd.net - 2016-03-17 21:32 +0000
    Re: Is this an error in python-babel or am I missing something? cl@isbd.net - 2016-03-17 22:40 +0000
      Re: Is this an error in python-babel or am I missing something? Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-17 19:31 -0700
        Re: Is this an error in python-babel or am I missing something? cl@isbd.net - 2016-03-18 10:41 +0000

#105157 — Is this an error in python-babel or am I missing something?

Fromcl@isbd.net
Date2016-03-17 21:32 +0000
SubjectIs this an error in python-babel or am I missing something?
Message-ID<tbkrrc-gam.ln1@esprimo.zbmc.eu>
I am getting the following error when running some code that uses
python-sqlkit.  This uses python-babel to handle dates for different
locales.

    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/sqlkit-0.9.6.1-py2.7.egg/sqlkit/widgets/table/columns.py", line 169, in cell_data_func_cb formatted_value = self.field.format_value(value)
      File "/usr/local/lib/python2.7/dist-packages/sqlkit-0.9.6.1-py2.7.egg/sqlkit/fields.py", line 1114, in format_value return dates.format_date(value, format=format or self.format, locale=self.locale)
      File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 569, in format_date return pattern.apply(date, locale)
      File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 892, in apply return self % DateTimeFormat(datetime, locale)
      File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 889, in __mod__ return self.format % other
      File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 948, in __getitem__ return self.format_milliseconds_in_day(num)
      File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 1029, in format_milliseconds_in_day self.value.minute * 60000 + self.value.hour * 3600000
    AttributeError: 'datetime.date' object has no attribute 'microsecond'

I'm handling a date in my sqlite database, *not* a datetime.  The
sqlkit code seems to be calling the correct method - format_date() -
in the python-babel dates.py file.

However it seems that python-babel ends up trying to hand the date
down to a method that's expecting a datetime.

I've tried searching for reports of this error but I can't see any
which makes me wonder if it's not a bug in python-babel, however if
it's not a bug then I'm confused about what has gone wrong.

Is it a bug or is sqlkit doing something wrong?

-- 
Chris Green
·

[toc] | [next] | [standalone]


#105167

Fromcl@isbd.net
Date2016-03-17 22:40 +0000
Message-ID<fcorrc-42n.ln1@esprimo.zbmc.eu>
In reply to#105157
cl@isbd.net wrote:
> I am getting the following error when running some code that uses
> python-sqlkit.  This uses python-babel to handle dates for different
> locales.
> 
>     Traceback (most recent call last):
> File "/usr/local/lib/python2.7/dist-packages/sqlkit-0.9.6.1-py2.7.egg/sqlkit/widgets/table/columns.py", 
> 
 
> line 169, in cell_data_func_cb formatted_value = self.field.format_value(value) 
> 
> File "/usr/local/lib/python2.7/dist-packages/sqlkit-0.9.6.1-py2.7.egg/sqlkit/fields.py", 
> line 1114, in format_value return dates.format_date(value, format=format 
> or self.format, locale=self.locale) 
> File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 569, in format_date 
> return pattern.apply(date, locale) 
> File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 892, in apply 
> return self % DateTimeFormat(datetime, locale) 
> File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 889, in __mod__ 
> return self.format % other 
> File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 948, in __getitem__ 
> return self.format_milliseconds_in_day(num) 
> File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 1029, in format_milliseconds_in_day 
> self.value.minute * 60000 + self.value.hour * 3600000 
>     AttributeError: 'datetime.date' object has no attribute 'microsecond'
> 
> I'm handling a date in my sqlite database, *not* a datetime.  The
> sqlkit code seems to be calling the correct method - format_date() -
> in the python-babel dates.py file.
> 
> However it seems that python-babel ends up trying to hand the date
> down to a method that's expecting a datetime.
> 
> I've tried searching for reports of this error but I can't see any
> which makes me wonder if it's not a bug in python-babel, however if
> it's not a bug then I'm confused about what has gone wrong.
> 
> Is it a bug or is sqlkit doing something wrong?
> 
Well, it's a sort of bug.  I had made the sqlkit code set the 'format'
field to something that it shouldn't be.  It should be "full", "long",
"medium", or "short".  Due to my misunderstanding I had set it to a
completely wrong value.  This makes python-babel fall over as above.

So, my mistake, but python-babel should have caught it.

-- 
Chris Green
·

[toc] | [prev] | [next] | [standalone]


#105174

FromRick Johnson <rantingrickjohnson@gmail.com>
Date2016-03-17 19:31 -0700
Message-ID<aab9a584-97cf-4be0-9b71-437223df91b8@googlegroups.com>
In reply to#105167
On Thursday, March 17, 2016 at 5:48:12 PM UTC-5, c...@isbd.net wrote:
> So, my mistake, but python-babel should have caught it.

Yeah, errors like that are a real pisser, and the further away from the source that they break, the more headache they become to resolve. They send you on a wild goose chase, and then after you've smacked your head against the desk for 10 mins, you find out it was something stupid that type checking could have easily prevented! If you find that this happens frequently, you may want to consider creating a wrapper to validate the inputs first, before sending them in -- there is no shame in doing this.

[toc] | [prev] | [next] | [standalone]


#105197

Fromcl@isbd.net
Date2016-03-18 10:41 +0000
Message-ID<jj2trc-jts.ln1@esprimo.zbmc.eu>
In reply to#105174
Rick Johnson <rantingrickjohnson@gmail.com> wrote:
> On Thursday, March 17, 2016 at 5:48:12 PM UTC-5, c...@isbd.net wrote:
> > So, my mistake, but python-babel should have caught it.
> 
> Yeah, errors like that are a real pisser, and the further away from the 
> source that they break, the more headache they become to resolve. They 
> send you on a wild goose chase, and then after you've smacked your head 
> against the desk for 10 mins, you find out it was something stupid that 
> type checking could have easily prevented! If you find that this happens 
> frequently, you may want to consider creating a wrapper to validate the 
> inputs first, before sending them in -- there is no shame in doing this. 
> 
In this case I'm running around like a headless chicken in sqlkit
anyway so I'm very *likely* to make the sort of mistake I made. :-)

However I'm getting on reasonably well with sqlkit, it's very clever
indeed with the instrospection it does so that a very few lines of
(my) code can produce a useful, working application.

-- 
Chris Green
·

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web