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

Adds logging for validation exceptions #53

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

racheldaniel
Copy link
Contributor

If a malformed request is sent to the dbt-server, we're currently unable to see any information other than the 422 Unprocessable Entity error.

I found this solution in a FastAPI github issue, and tested running the following curl command locally, omitting an expected field:

curl localhost:8585/push -H 'Content-Type: application/json' -d '{"state_id":"c88a8c249f7675b008a24ad18b4c33ec","body":{"file_1": {"contents":"value", "hash":""}}}'

Before:
unhelpful_logs

After:
logs_with_error_details

@@ -174,6 +175,14 @@ class SQLConfig(BaseModel):
sql: str


@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc: RequestValidationError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is dope @racheldaniel!! Totally a question from a place of my own ignorance: why is this a 422 vs. a 400? Is it possible that the 422 response below could actually change the response code generated by the app, or would every validation error result in a 422?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drewbanin Thanks, and a great question!

My understanding is that the FastAPI RequestValidationError that we're catching would normally always yield a 422: Unprocessable Entity if left unhandled. This error class is an extension of the pydantic class ValidationError-- I think we're pretty safe to throw a 422 for these specific exceptions.

As far as 400 vs. 422-- I'm using the 422 only because that was what was being thrown organically. I would be more than fine throwing a 400-- we're not distinguishing between syntactic and semantic inaccuracies here, which is what the difference is supposed to be. FastAPI throws as 422 whether you leave a field out of the body or send the wrong data type, which seems odd to me.

I have zero preference here, so if it feels better to others to go ahead and make this a 400 I'm totally down. However there shouldn't be any issue with changing other errors to 422s as far as I'm aware!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok word! If the underlying exception would result in a 422, then i have no problem at all with generating our own exception instead! Thanks so much for the additional info :)

@racheldaniel racheldaniel merged commit ae141fd into main Jul 26, 2022
@racheldaniel racheldaniel deleted the racheld/hotfix/log-validation-errors branch July 26, 2022 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants