On Sunday, May 31, 2020 at 7:07:02 PM UTC-7, Aikido Guy wrote:
>
> On Sunday, May 31, 2020 at 10:05:30 PM UTC-4, Aikido Guy wrote:
>>
>> A TicketQuery (working before upgrade to Trac 1.4.1) has triggered the 
>> following error message in Trac 1.4.1 (the log file contains):
>>
>> ERROR: Macro TicketQuery(...)
>> trac/wiki/formatter.py line 818 in _macro_formatter
>> ...
>> trac/ticket/query.py line 1406
>> trac/ticket/query.py line 334
>> val = from_utimestamp(int(val)) if val else None
>>
>> ValueError: invalid literal for int() with base 10: '2018/07/03'
>>
>> Notes:
>> (1) I am ordering by a column that use to be of type "text" and was then 
>> formatted by a plugin (if I remember correctly... it has been about 6 years)
>> (2) The new column is now of type "time" with format "date"
>>
>> Questions:
>> (1) Do I need to change the backing sqlite database for this column type 
>> change from "text" to "time"?
>> (2) Is there a little SQL script or something that you already have 
>> available that could help me with this process if I need to do it myself?
>>
>
> Forgot to mention that I also saw #12325 that may be related...
>
> Kindly,
> Aikido Guy
>

You were probably using DateFieldPlugin, and encountering the problem 
described in this ticket:
https://trac-hacks.org/ticket/11856

So, yes, like you've already hinted at, if you want to use a 
TicketCustomField of type time, you'll have to migrate your data. Or if 
you've created a special column for time data, either directly or via a 
plugin. In the latter case, you'll need to change the column type from text 
to int64 (and type defined in Trac, which maps to appropriate types in each 
supported DB).

If you are using a custom field of type time, then no need to worry about 
the database type because all data in the ticket_custom table gets stored 
as text. Example:

[ticket-custom]
time1 = time
time1.format = date

Created a ticket #155 with the "time1" field having value "May 1, 2020":

$ litecli ../tracenvs/proj-1.3/db/trac.db
Version: 1.2.0
Mail: https://groups.google.com/forum/#!forum/litecli-users
GitHub: https://github.com/dbcli/litecli
../tracenvs/proj-1.3/db/trac.db> SELECT * FROM ticket_custom WHERE 
ticket=155 AND name='time1'
+--------+-------+--------------------+
| ticket | name  | value              |
+--------+-------+--------------------+
| 155    | time1 | 001588316400000000 |
+--------+-------+--------------------+
1 row in set
Time: 0.010s


I did some quick investigation on conversion:

>>> from trac.util.datefmt import parse_date, to_utimestamp
>>> d = parse_date('2018/07/03'.replace('/', '-'))
>>> d
datetime.datetime(2018, 7, 3, 0, 0, tzinfo=<LocalTimezone "PDT" -1 day, 
17:00:00>)
>>> t = to_utimestamp(d)
>>> t
1530601200000000

You can convert "t" to a string and insert into the ticket_custom table.

You should be okay if your server is in approximately the same timezone as 
your users, but if not, and if you care, you need to determine who inserted 
the data and what timezone they were in. That sounds painful.

- Ryan

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to trac-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/trac-users/c6e586fe-b03c-4852-9fa3-b81ae9de7b57%40googlegroups.com.

Reply via email to