Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog Plugin still errors with TypeError: can't compare offset-naive and offset-aware datetimes #7748

Closed
4 tasks done
Andre601 opened this issue Nov 25, 2024 · 6 comments
Closed
4 tasks done
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@Andre601
Copy link
Contributor

Andre601 commented Nov 25, 2024

Context

Continuation of #7725 which seems to still be present.

Bug description

When executing a build does the build error with TypeError: can't compare offset-naive and offset-aware datetime

Full Stacktrace from mkdocs build:

$ mkdocs build
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: D:\GitHub\reproduction\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 "D:\GitHub\reproduction\venv\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "D:\GitHub\reproduction\venv\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\mkdocs\__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
  File "D:\GitHub\reproduction\venv\Lib\site-packages\mkdocs\commands\build.py", line 292, in build
    files = config.plugins.on_files(files, config=config)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\mkdocs\plugins.py", line 593, in on_files
    return self.run_event('files', files, config=config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\mkdocs\plugins.py", line 566, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\material\plugins\blog\plugin.py", line 133, in on_files
    self.blog.posts = sorted(
                      ^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\material\plugins\blog\plugin.py", line 444, in _resolve_posts
    if not self._is_excluded(post):
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\material\plugins\blog\plugin.py", line 373, in _is_excluded
    return post.config.date.created > datetime.now()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare offset-naive and offset-aware datetimes

The issue is most likely the usage of date: yyyy-mm-dd without any timezones or time in general.

Note: Only mkdocs build is affected. mkdocs serve runs without any errors reported.

Related links

Reproduction

9.5.46-blog-date-issue.zip

Steps to reproduce

  1. Install Material for MkDocs 9.5.46
  2. Setup Blog plugin
  3. Create a post with a date frontmatter in the format yyyy-mm-dd
  4. Execute mkdocs build

Browser

No response

Before submitting

@squidfunk
Copy link
Owner

Thanks for reporting. Help appreciated! It's likely the same fix as for #7725. I did not expect this to be such a nuisance to fix. I'm currently short on time, so if anybody has a few minutes on his hands, PR appreciated.

@squidfunk squidfunk added the bug Issue reports a bug label Nov 25, 2024
@perpil
Copy link
Contributor

perpil commented Nov 25, 2024

Working on a fix, it appears with draft_if_future_date: true it is still using non timezone aware dates.

@perpil
Copy link
Contributor

perpil commented Nov 25, 2024

PR #7749 out and tested against the repro. I've looked for other instances of datetime and think I've finally got them all.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Nov 25, 2024
@squidfunk
Copy link
Owner

Keeping open until released.

@squidfunk squidfunk reopened this Nov 25, 2024
@squidfunk
Copy link
Owner

Released as part of 9.5.47.

@Andre601
Copy link
Contributor Author

Andre601 commented Dec 1, 2024

Just want to quickly confirm that the CI doesn't error anymore, so this issue really seems to be fixed now.
Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

3 participants