Hypercorn fails to load ASGI app in campaign_analyst with "Attribute 'app' not found"

denisaiagent
PRO

4 months ago

We are deploying a Python service (campaign_analyst) on Railway using Quart and Hypercorn. The build initially failed due to a COPY error in the Dockerfile, which we resolved by adjusting the Root Directory to campaign_analyst and updating the Dockerfile to COPY requirements.txt .. However, after the build succeeded, the deployment fails with the following error in the Deploy Logs:

text

CollapseWrapCopy

ERROR: Error loading ASGI app. Attribute "app" not found in module "campaign_analyst".

Despite confirming that the app attribute is defined in our code, Hypercorn cannot find it. We suspect an issue with the import path or context due to the Root Directory configuration.

Error messages

  • Build Logs (before fix):

    text

    CollapseWrapCopy

    ✕ [3/6] COPY campaign_analyst/requirements.txt . failed to calculate checksum of ref jdi6neqdlo6j7ul48gbdpcptj::rnvr6llkqt3yd3vg0umb8kx45: "/campaign_analyst/requirements.txt": not found

    This was resolved by updating the Dockerfile and Root Directory.

  • Deploy Logs (current error):

    text

    CollapseWrapCopy

    ERROR: Error loading ASGI app. Attribute "app" not found in module "campaign_analyst".

Logs (build and/or deploy)

  • Build Logs (latest): The build now succeeds after adjusting the Dockerfile to COPY requirements.txt . and setting the Root Directory to campaign_analyst.

  • Deploy Logs (latest):

    text

    CollapseWrapCopy

    Starting Container ERROR: Error loading ASGI app. Attribute "app" not found in module "campaign_analyst".

Link to GitHub repo/code or template you're using, if applicable

The repository is private, but here is the relevant structure and code:

  • Directory structure:

    text

    CollapseWrapCopy

    Bandstream-AiAgent/ ├── campaign_analyst/ │ ├── requirements.txt │ ├── campaign_analyst.py │ ├── Dockerfile │ ├── Procfile │ └── __init__.py ├── campaign_supervisor/ │ ├── ... └── ...

  • campaign_analyst/Procfile:

    text

    CollapseWrapCopy

    web: hypercorn campaign_analyst:app --bind 0.0.0.0:$PORT

  • campaign_analyst/Dockerfile:

    text

    CollapseWrapCopy

    FROM python:3.9-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . RUN touch campaign_analyst/__init__.py EXPOSE $PORT CMD ["hypercorn", "campaign_analyst:app", "--bind", "0.0.0.0:$PORT"]

  • campaign_analyst/campaign_analyst.py (relevant excerpt):

    python

    CollapseWrapCopy

    from quart import Quart app = Quart(__name__) @app.route("/analyze", methods=["POST"]) async def analyze(): # Route logic here pass @app.route("/health") async def health_check(): return jsonify({"status": "ok"})

Project

  • Project ID: Not shared for security reasons.

  • Service: campaign_analyst

Urgency

  • High : This service is critical for our application, and we need to resolve this issue to proceed with deployment.

Visibility

  • Make Thread Visible to Railway Team Only (Private) : For sensitive info, such as invoices or personal data.

Why can't Hypercorn find the app attribute in the campaign_analyst module, so app = Quart(__name__) is correctly defined in campaign_analyst.py? Is there an issue with the import context or the root directory configuration that could be causing this issue? Thanks for your help !

Denis

Closed

1 Replies

3 months ago

Hey!

This is an issue with your project/application. Unfortunately, we're unable to offer first-party support for issues unrelated to the Railway product or platform.

Other communities such as Stackoverflow might be able to help you out further.

Best,
Brody


Status changed to Awaiting User Response railway[bot] 4 months ago


Status changed to Closed brody 4 months ago


Hypercorn fails to load ASGI app in campaign_analyst with "Attribute 'app' not found" - Railway Help Station