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

Bug: Reload option sometimes triggers TypeError: not all arguments converted during string formatting #1364

Closed
pySilver opened this issue Apr 11, 2024 · 1 comment · Fixed by #1360
Labels
bug Something isn't working

Comments

@pySilver
Copy link

Describe the bug

I am not sure what really causes this error. My wild guess is that it is somehow related to the fact that I'm using structlog that was configured per official instructions described here: https://faststream.airt.ai/latest/getting-started/logging/?h=structlog#structlog-example. Error does not happen all the time but quite frequently during development.

How to reproduce

# logger.py
import sys

import structlog

from faststream import context


def merge_contextvars(
    logger: structlog.types.WrappedLogger,
    method_name: str,
    event_dict: structlog.types.EventDict,
) -> structlog.types.EventDict:
    event_dict["extra"] = event_dict.get(
        "extra",
        context.get("log_context", {}),
    )
    return event_dict


shared_processors = [
    merge_contextvars,
    structlog.processors.add_log_level,
    structlog.processors.StackInfoRenderer(),
    structlog.dev.set_exc_info,
    structlog.processors.TimeStamper(fmt="iso"),
]

if sys.stderr.isatty():
    processors = shared_processors + [structlog.dev.ConsoleRenderer()]
else:
    processors = shared_processors + [
        structlog.processors.dict_tracebacks,
        structlog.processors.JSONRenderer(),
    ]

structlog.configure(
    processors=processors,
    logger_factory=structlog.PrintLoggerFactory(),
    cache_logger_on_first_use=False,
)
logger = structlog.get_logger()

integration with an app:

# serve.py
import logging

from faststream import FastStream
from faststream.nats import NatsBroker

from logger import logger

broker = NatsBroker(
    "nats://localhost:4222",
    logger=logger,
    log_level=logging.DEBUG,
    description="IO-bound service",
)
broker.include_router(router)
app = FastStream(broker, logger=logger)
...

And/Or steps to reproduce the behavior:

  1. Integrate structlog per documentation
  2. Run the app with --reload option faststream run serve:app --reload

Expected behavior
No TypeError on reload.

Observed behavior

2024-04-11T16:55:56.073888Z [info     ] FastStream app started successfully! To exit, press CTRL+C extra={}
Traceback (most recent call last):

  File "/Users/Silver/.pyenv/versions/3.12.1/envs/jetstream/bin/faststream", line 8, in <module>
    sys.exit(cli())
             ^^^^^

  File "/Users/Silver/.pyenv/versions/3.12.1/envs/jetstream/lib/python3.12/site-packages/faststream/cli/main.py", line 137, in run
    ).run()
      ^^^^^

  File "/Users/Silver/.pyenv/versions/3.12.1/envs/jetstream/lib/python3.12/site-packages/faststream/cli/supervisors/basereload.py", line 88, in run
    if self.should_restart():  # pragma: no branch
       ^^^^^^^^^^^^^^^^^^^^^

  File "/Users/Silver/.pyenv/versions/3.12.1/envs/jetstream/lib/python3.12/site-packages/faststream/cli/supervisors/watchfiles.py", line 89, in should_restart
    logger.info(message % tuple(unique_paths))
                ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~

TypeError: not all arguments converted during string formatting

Environment
Running FastStream 0.4.6 with CPython 3.12.1 on Darwin

@pySilver pySilver added the bug Something isn't working label Apr 11, 2024
@Lancetnik
Copy link
Member

Lancetnik commented Apr 11, 2024

It doesn't related to structlog.

Seems like Path() object can't be casted to str in your case. I'll try to fix it by manual casting, but not sure. I am just can't reproduce your case, sorry

@Lancetnik Lancetnik mentioned this issue Apr 11, 2024
9 tasks
github-merge-queue bot pushed a commit that referenced this issue Apr 13, 2024
* chore: update dependencies

* docs (#607): delay Publisher feature

* WIP: Add separate public and all apis

* Add symlink for public_api directory from api directory

* fix: do not block at application startup

* Export pubic API only from certain init files

* docs: new middlewares

* fix: correct ExceptionGroup processing

* fix (#1364): explicit cast all Paths to str

* Include only __all__ imports in public API

* fix: correct Acknowledgement logic

* fix: correct Acknowledgement logic

* lint: fix mypy

* Proofread docs

---------

Co-authored-by: Kumaran Rajendhiran <kumaran@airt.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants