Skip to content

Blog plugin failing with TypeError: can't compare offset-naive and offset-aware datetimes on 9.5.45 #7725

@mvelikikh

Description

@mvelikikh

Context

No response

Bug description

mkdocs build --strict fails on 9.5.45 with the error below:

mkdocs build -s
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: D:\temp\20241120\mkdocs\site
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\mkdocs\__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\mkdocs\commands\build.py", line 292, in build
    files = config.plugins.on_files(files, config=config)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\mkdocs\plugins.py", line 593, in on_files
    return self.run_event('files', files, config=config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\mkdocs\plugins.py", line 566, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\material\plugins\blog\plugin.py", line 133, in on_files
    self.blog.posts = sorted(
                      ^^^^^^^
TypeError: can't compare offset-naive and offset-aware datetimes

9.5.38 works fine.
I constructed a minimal reproduction test case, and based on this, the error is thrown when I have two formats of date.created:

  1. yyyy-mm-dd (e.g. created: 2024-09-06)
  2. yyyy-mm-ddThh:mi:ss (e.g. created: 2019-02-25T04:25:00)

Both formats are supported per the documentation: https://squidfunk.github.io/mkdocs-material/plugins/blog/#meta.date

If I remove any of the files and keep only one format, there is no error.

Related links

Reproduction

9.5.45-typerror-cannot-compare-datetimes.zip

Steps to reproduce

  1. pip install . (the reproduction file has pyproject.toml)
  2. mkdocs build --strict - should fail ❌
  3. pip install mkdocs-material==9.5.38
  4. mkdocs build --strict - should work✔

Browser

Firefox

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions