-
Notifications
You must be signed in to change notification settings - Fork 16.4k
AIP-81 Add Insert Multiple Pools API #44121
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
Merged
pierrejeambrun
merged 9 commits into
apache:main
from
jason810496:feature/AIP-81/add-bulk-insert-pools-api
Nov 22, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0c71786
Add bulk post pools, refactor post pool
jason810496 86e324c
Add 409 case for TestPostPool
jason810496 6443989
Add test for bulk post pools
jason810496 01ba623
Remove unused status code, rename post_body to body
jason810496 6d49618
Refactor duplicate pool insert handling
jason810496 dcd81d3
Add global database exception handler for fastapi
jason810496 531416b
Remove manual handle for unique constraint exc
jason810496 955acb8
Refactor test_pools
jason810496 c9b67c1
Fix bound for TypeVar, type for comment
jason810496 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from typing import Generic, TypeVar | ||
|
|
||
| from fastapi import HTTPException, Request, status | ||
| from sqlalchemy.exc import IntegrityError | ||
|
|
||
| T = TypeVar("T", bound=Exception) | ||
|
|
||
|
|
||
| class BaseErrorHandler(Generic[T], ABC): | ||
| """Base class for error handlers.""" | ||
|
|
||
| def __init__(self, exception_cls: T) -> None: | ||
| self.exception_cls = exception_cls | ||
|
|
||
| @abstractmethod | ||
| def exception_handler(self, request: Request, exc: T): | ||
| """exception_handler method.""" | ||
| raise NotImplementedError | ||
|
|
||
|
|
||
| class _UniqueConstraintErrorHandler(BaseErrorHandler[IntegrityError]): | ||
| """Exception raised when trying to insert a duplicate value in a unique column.""" | ||
|
|
||
| def __init__(self): | ||
| super().__init__(IntegrityError) | ||
| self.unique_constraint_error_messages = [ | ||
| "UNIQUE constraint failed", # SQLite | ||
| "Duplicate entry", # MySQL | ||
| "violates unique constraint", # PostgreSQL | ||
| ] | ||
|
|
||
| def exception_handler(self, request: Request, exc: IntegrityError): | ||
| """Handle IntegrityError exception.""" | ||
| exc_orig_str = str(exc.orig) | ||
| if any(error_msg in exc_orig_str for error_msg in self.unique_constraint_error_messages): | ||
| raise HTTPException( | ||
| status_code=status.HTTP_409_CONFLICT, | ||
| detail="Unique constraint violation", | ||
| ) | ||
|
|
||
|
|
||
| DatabaseErrorHandlers = [ | ||
| _UniqueConstraintErrorHandler(), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.