Saluev / suppgram

Simple Telegram-based support system written in Python
https://suppgram.readthedocs.io
MIT License
23 stars 2 forks source link

Builder creation failed with Python 3.12: "Builder finalization failed" error #2

Open pa111111 opened 1 month ago

pa111111 commented 1 month ago

I am encountering an issue when trying to use the suppgram library in my Python project with Python 3.12. The builder creation process fails with the error "Builder finalization failed." Here are the details

Steps to Reproduce:

  1. Install suppgram via pip in a virtual environment using Python 3.12.
  2. Use the following code to configure and build the suppgram builder:

import asyncio import logging

from suppgram.builder import Builder

logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(name)

async def main(): try: logger.debug("Starting to build the suppgram builder.") builder = Builder()

    logger.debug("Configuring SQLAlchemy storage.")
    builder = builder.with_sqlalchemy_storage("sqlite+aiosqlite:///test.db")
    if builder is None:
        raise ValueError("SQLAlchemy storage configuration failed")
    logger.debug(f"SQLAlchemy storage configured: {builder}")

    logger.debug("Configuring Telegram manager frontend.")
    builder = builder.with_telegram_manager_frontend("*******", *******)
    if builder is None:
        raise ValueError("Telegram manager frontend configuration failed")
    logger.debug(f"Telegram manager frontend configured: {builder}")

    logger.debug("Configuring Telegram customer frontend.")
    builder = builder.with_telegram_customer_frontend("**********")
    if builder is None:
        raise ValueError("Telegram customer frontend configuration failed")
    logger.debug(f"Telegram customer frontend configured: {builder}")

    logger.debug("Configuring Telegram agent frontend.")
    builder = builder.with_telegram_agent_frontend(["************"])
    if builder is None:
        raise ValueError("Telegram agent frontend configuration failed")
    logger.debug(f"Telegram agent frontend configured: {builder}")

    logger.debug("Finalizing the builder.")
    builder = builder.build()
    if builder is None:
        raise ValueError("Builder finalization failed")
    logger.debug(f"Builder finalized: {builder}")

    if builder is not None:
        logger.debug("Builder created successfully")
        await builder.start()
        await asyncio.Event().wait()  # This will keep the script running
    else:
        logger.error("Builder creation failed")
except Exception as e:
    logger.exception("An error occurred during builder creation or execution")
    print(f"An error occurred: {e}")

if name == "main": asyncio.run(main())

Observed Behavior: The process fails with the following error message: ValueError: Builder finalization failed

Logs: DEBUG:main:Starting to build the suppgram builder. DEBUG:main:Configuring SQLAlchemy storage. DEBUG:main:Configuring Telegram manager frontend. DEBUG:main:Configuring Telegram customer frontend. DEBUG:main:Configuring Telegram agent frontend. DEBUG:main:Finalizing the builder. INFO:suppgram.builder:Initializing Telegram customer frontend DEBUG:main:Builder finalized: None ERROR:main:Builder creation failed

Environment:

OS: Windows 10 Python Version: 3.12 Suppgram Version: [Specify the version you are using] Other relevant packages: httpx

Additional Information: I've checked the tokens and IDs multiple times, and they seem to be correct. I also tried running individual components separately, and they work fine. The issue seems to occur during the build() method.

Any guidance or suggestions to resolve this issue would be greatly appreciated.

Saluev commented 1 month ago

Hi Pavel,

It seems odd that this code

    if builder is None:
        raise ValueError("Builder finalization failed")

passes and then in the next line it logs Builder finalized: None. Are you sure you provided your source code as is?

Also, Builder methods always return Builder, never Builder | None. Maybe you could run mypy through your code to check if you are missing something.