Cannot use postgres due to bug "can't compare offset-naive and offset-aware datetimes" at webutils.py", line 577

Jamie Love jlove at nsquared.nz
Thu Aug 21 03:39:01 UTC 2025


An update for any future readers.

The database itself has the timezone on the relevant columns:

kallithea=# \d repositories
                                            Table "public.repositories"
      Column      |           Type           | Collation | Nullable |                    Default
------------------+--------------------------+-----------+----------+-----------------------------------------------
repo_id          | bigint                   |           | not null | nextval('repositories_repo_id_seq'::regclass)
repo_name        | text                     |           |          |
repo_state       | text                     |           |          |
clone_uri        | text                     |           |          |
repo_type        | text                     |           |          |
user_id          | bigint                   |           |          |
private          | boolean                  |           |          |
statistics       | boolean                  |           |          |
downloads        | boolean                  |           |          |
description      | text                     |           |          |
created_on       | timestamp with time zone |           |          |
updated_on       | timestamp with time zone |           |          |
landing_revision | text                     |           |          |
changeset_cache  | bytea                    |           |          |
fork_id          | bigint                   |           |          |
group_id         | bigint                   |           |          |


This is the state of the database when exported from sqlite/imported into postgres. I can see that this is not the same if I build the database from Kallithea directly (these fields are set to "without timezone")

I used pgloader to transfer the data across to postgres from sqlite.
Solution was straightforward. Building the DB using Kallithea and then using the following load script for pgloader avoids the schema rebuild:


load database
     from sqlite:///mnt/kallithea.db
     into postgresql://kallithea:pass@vcs:5432/kallithea

with truncate, data only

  set work_mem to '16MB', maintenance_work_mem to '512 MB';


Regards
Jamie


On Tue, 19 Aug 2025, at 12:15 PM, Jamie Love wrote:
> Hi there,
> 
> Before going into the code and fixing this myself, I was wondering if anyone had come across the following error before. This is with the latest version of the code from the repository.
> 
> This occurs with Postgres, but not with SQLite (we have had to roll back from postgres to SQLite because of this error):
> 
> *  **File "/home/kallithea/kallithea/kallithea/lib/webutils.py", line 577, in age*
> *    if prevdate > now:*
> *TypeError: can't compare offset-naive and offset-aware datetimes*
> *Traceback (most recent call last):*
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/tg/appwrappers/session.py", line 71, in __call__
>     response = self.next_handler(controller, environ, context)
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/tg/appwrappers/i18n.py", line 71, in __call__
>     return self.next_handler(controller, environ, context)
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/tg/wsgiapp.py", line 243, in _dispatch
>     return controller(environ, context)
>   File "/home/kallithea/kallithea/kallithea/controllers/base.py", line 531, in __call__
>     return super(BaseController, self).__call__(environ, context)
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/tg/controllers/dispatcher.py", line 118, in __call__
>     response = self._perform_call(context)
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/tg/controllers/dispatcher.py", line 107, in _perform_call
>     r = self._call(action, params, remainder=remainder, context=context)
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/tg/controllers/decoratedcontroller.py", line 129, in _call
>     output = controller_caller(context_config, bound_controller_callable, remainder, params)
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/tg/controllers/decoration.py", line 21, in _decorated_controller_caller
>     return application_controller_caller(tg_config, controller, remainder, params)
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/tg/configurator/components/dispatch.py", line 114, in _call_controller
>     return controller(*remainder, **params)
>   File "/home/kallithea/kallithea/kallithea/controllers/admin/repo_groups.py", line 278, in show_by_name
>     return self.show(group_name)
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/decorator.py", line 232, in fun
>     return caller(func, *(extras + args), **kw)
>   File "/home/kallithea/kallithea/kallithea/lib/auth.py", line 575, in __wrapper
>     return func(*fargs, **fkwargs)
>   File "/home/kallithea/kallithea/kallithea/controllers/admin/repo_groups.py", line 291, in show
>     c.data = RepoModel().get_repos_as_dict(repos_list,
>   File "/home/kallithea/kallithea/kallithea/model/repo.py", line 178, in get_repos_as_dict
>     "last_change": last_change(repo.last_db_change),
>   File "/home/kallithea/kallithea/kallithea/model/repo.py", line 130, in last_change
>     return _render("last_change", last_change)
>   File "/home/kallithea/kallithea/kallithea/model/repo.py", line 102, in _render_datatable
>     return tmpl.render_unicode(
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/mako/template.py", line 439, in render_unicode
>     return runtime._render(
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/mako/runtime.py", line 874, in _render
>     _render_context(
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/mako/runtime.py", line 920, in _render_context
>     _exec_template(callable_, context, args=args, kwargs=kwargs)
>   File "/home/kallithea/kallithea/venv/lib/python3.9/site-packages/mako/runtime.py", line 943, in _exec_template
>     callable_(context, *args, **kwargs)
>   File "data_table__dt_elements_html", line 133, in render_last_change
> 
> 
> Thanks
> Jamie
> _______________________________________________
> kallithea-general mailing list
> kallithea-general at sfconservancy.org
> https://lists.sfconservancy.org/mailman/listinfo/kallithea-general
> 


Jamie Love

N-Squared Software




mobilePhone
+64 (21) 063 5462 <tel:+64 (27) 492 7866>
emailAddress
jlove at nsquared.nz
website
nsquared.nz

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sfconservancy.org/pipermail/kallithea-general/attachments/20250821/a23a9b0f/attachment-0001.html>


More information about the kallithea-general mailing list