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

2016-03-20 Thread cl
c...@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 * 6 + self.value.hour * 360 
> 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
·
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-03-19 Thread cl
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 * 6 + self.value.hour * 360
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
·
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-03-19 Thread Rick Johnson
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-03-19 Thread cl
Rick Johnson  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
·
-- 
https://mail.python.org/mailman/listinfo/python-list