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

When use warm-up cache error 400 bad request #30900

Closed
3 tasks done
AnTapTanhCode opened this issue Nov 12, 2024 · 12 comments · Fixed by #31173
Closed
3 tasks done

When use warm-up cache error 400 bad request #30900

AnTapTanhCode opened this issue Nov 12, 2024 · 12 comments · Fixed by #31173

Comments

@AnTapTanhCode
Copy link

AnTapTanhCode commented Nov 12, 2024

Bug description

When i use celery warm-up cache it is error 405 Method Not Allowed. I did try 28706, but affter i getting error 400 bad request
master:
image
celery:
image
. anyone help me?
edit:
i trying superset-4.1.0rc4 but it is still similar.

Screenshots/recordings

No response

Superset version

4.0.2

Python version

3.10

Node version

I don't know

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Copy link

dosubot bot commented Nov 12, 2024

The 400 Bad Request error you're encountering when using the Celery warm-up cache in Superset version 4.0.2 is likely due to a validation error in the request body. The warm_up_cache endpoint expects a JSON payload that conforms to the DatasetCacheWarmUpRequestSchema. If the request body does not match this schema, a ValidationError is raised, resulting in a 400 error response.

Initially, you received a 405 Method Not Allowed error, which suggests that the HTTP method used was incorrect. The warm_up_cache endpoint only allows the PUT method. Once you corrected the method to PUT, the request proceeded to the next stage, where it encountered the 400 error due to the invalid request body.

To resolve the 400 error, ensure that your request body is correctly formatted according to the expected schema:

{
    "db_name": "string",  // The name of the database where the table is located
    "table_name": "string",  // The name of the table to warm up cache for
    "dashboard_id": integer,  // The ID of the dashboard to get filters for when warming cache
    "extra_filters": "string"  // Extra filters to apply when warming up cache
}

The fields db_name and table_name are required, while dashboard_id and extra_filters are optional [1][2].

To continue talking to Dosu, mention @dosu.

@AnTapTanhCode
Copy link
Author

what is file fix it? @dosu

Copy link

dosubot bot commented Nov 13, 2024

To fix the 400 Bad Request error when using the Celery warm-up cache in Superset, you should modify the superset/charts/api.py file. The error is likely caused by a validation error when loading the request JSON using ChartCacheWarmUpRequestSchema. Ensure that the JSON payload you are sending to the /warm_up_cache endpoint is correctly structured according to the schema [1].

To continue talking to Dosu, mention @dosu.

@AnTapTanhCode
Copy link
Author

so what will i do? @dosu

Copy link

dosubot bot commented Nov 13, 2024

Ensure that the JSON payload you are sending to the /warm_up_cache endpoint is correctly structured according to the DatasetCacheWarmUpRequestSchema. Here's what you need to do:

  1. Check the JSON Request Body: Make sure it includes all required fields and is correctly formatted. The required fields are db_name and table_name. Optional fields include dashboard_id and extra_filters.

  2. Validate Data Types: Ensure that the data types of the fields match the expected types:

    • db_name and table_name should be strings.
    • dashboard_id should be an integer.
    • extra_filters should be a string.
  3. Use the Correct HTTP Method: The warm_up_cache endpoint requires the PUT method.

By following these steps, you should be able to resolve the 400 Bad Request error. If you continue to encounter issues, review any error messages returned to identify specific fields causing the problem [1][2].

To continue talking to Dosu, mention @dosu.

@AnTapTanhCode
Copy link
Author

where can i add dashboard_id and extra_filters? @dosu

Copy link

dosubot bot commented Nov 13, 2024

You can add dashboard_id and extra_filters as optional fields in the JSON payload for the /warm_up_cache endpoint. The JSON payload should include these fields along with the required fields db_name and table_name. Here's an example of how the JSON payload might look:

{
  "db_name": "your_database_name",
  "table_name": "your_table_name",
  "dashboard_id": "your_dashboard_id",  // Optional
  "extra_filters": {                    // Optional
    "filter_key": "filter_value"
  }
}

These fields are accessed in the code using body.get("dashboard_id") and body.get("extra_filters"), indicating that they are optional [1].

To continue talking to Dosu, mention @dosu.

@AnTapTanhCode
Copy link
Author

can you step by step for me? @dosu

Copy link

dosubot bot commented Nov 13, 2024

Certainly! Here's a step-by-step guide to help you resolve the 400 Bad Request error when using the Celery warm-up cache in Superset:

  1. Identify the Endpoint:

    • Ensure you are sending your request to the correct endpoint, which is /warm_up_cache.
  2. Use the Correct HTTP Method:

    • The endpoint requires a PUT request. Make sure your HTTP method is set to PUT.
  3. Prepare the JSON Payload:

    • Your request body should be a JSON object that matches the DatasetCacheWarmUpRequestSchema. Here's a template:
    {
      "db_name": "your_database_name",  // Required
      "table_name": "your_table_name",  // Required
      "dashboard_id": 123,              // Optional, replace with an integer
      "extra_filters": "your_filters"   // Optional, replace with a string
    }
  4. Ensure Required Fields are Present:

    • db_name and table_name are required fields. Make sure they are included and correctly spelled in your JSON payload.
  5. Validate Data Types:

    • db_name and table_name should be strings.
    • dashboard_id should be an integer if provided.
    • extra_filters should be a string if provided.
  6. Send the Request:

    • Use a tool like curl, Postman, or your application code to send the PUT request with the JSON payload to the /warm_up_cache endpoint.
  7. Check for Errors:

    • If you still encounter a 400 error, check the error message returned by the server. It should indicate which part of the request is invalid.

By following these steps, you should be able to correctly format your request and resolve the 400 Bad Request error. If you encounter any specific error messages, they can provide further clues on what might be wrong with your request.

To continue talking to Dosu, mention @dosu.

@AnTapTanhCode
Copy link
Author

no i did set superset-config.py:

class CeleryConfig:
    broker_url = 'redis://localhost:6379/1'
    imports = (
        "superset.sql_lab",
        "superset.tasks.scheduler",
        "superset.tasks.thumbnails",
        "superset.tasks.cache",
    )
    result_backend = 'redis://localhost:6379/6'
    worker_prefetch_multiplier = 1
    task_acks_late = True
    beat_schedule = {
        "cache-warmup-hourly": {
        "task": "cache-warmup",
        "schedule": crontab(minute='*', hour='*'),  
        "kwargs": {"strategy_name": "dummy"}, 
        },
    }

@dosu

Copy link

dosubot bot commented Nov 13, 2024

Your superset-config.py configuration for the Celery cache-warmup task looks mostly correct. The kwargs parameter is set with the strategy_name as "dummy", which is a valid strategy for the cache warm-up task. This strategy will warm up all charts by fetching all charts in the database [1].

If you're still encountering issues, ensure that:

  1. Redis is Running: Verify that your Redis server is running and accessible at localhost:6379.

  2. Celery Worker is Running: Make sure that your Celery worker is running and configured to use the same broker_url and result_backend.

  3. Check Logs: Look at the logs for both Superset and Celery to identify any errors or warnings that might provide more context on the issue.

  4. Task Registration: Ensure that the cache-warmup task is correctly registered and available in your Celery worker. You can list available tasks using the celery -A superset.tasks worker --loglevel=info command.

If these steps don't resolve the issue, consider checking for any specific error messages in the logs that could indicate the root cause of the problem.

To continue talking to Dosu, mention @dosu.

@AnTapTanhCode
Copy link
Author

Yedd it was fix in#31173. Thank you @nsivarajan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant