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

feat: on Price create, create (or get) Location, and link them #36

Merged
merged 4 commits into from
Nov 21, 2023

Conversation

raphodn
Copy link
Member

@raphodn raphodn commented Nov 16, 2023

What

  • new relationship Price.location
  • new background task create_price_location
  • on Price create, we first create (or get if existing) a Location, and then link them

@raphodn raphodn self-assigned this Nov 16, 2023
@raphodn raphodn requested a review from raphael0202 November 16, 2023 15:27
@raphodn raphodn linked an issue Nov 16, 2023 that may be closed by this pull request
4 tasks
@raphodn raphodn force-pushed the raphodn/price-location-relationship branch from 7d9564f to 87399e7 Compare November 16, 2023 16:18
@raphodn raphodn force-pushed the raphodn/price-location-relationship branch 2 times, most recently from 688eec5 to f5cbcb0 Compare November 16, 2023 18:29
from app.schemas import LocationCreate, PriceBase


def create_price_location(db: Session, price: PriceBase):
Copy link
Contributor

Choose a reason for hiding this comment

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

are Session objects thread-safe? As I assume we're using threads to launch a task in the background.

Copy link
Member Author

@raphodn raphodn Nov 20, 2023

Choose a reason for hiding this comment

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

No idea 😅
I used the background tasks example from the fastAPI tutorials: https://fastapi.tiangolo.com/tutorial/background-tasks/

edit : it seems a possible solution: fastapi/fastapi#4956 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

though they do recommend to create a new db session here: fastapi/fastapi#8502 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

added it to #31

Base automatically changed from raphodn/location-model to main November 20, 2023 23:52
@raphodn raphodn force-pushed the raphodn/price-location-relationship branch from f5cbcb0 to 757f1a4 Compare November 20, 2023 23:54
@raphodn raphodn merged commit 003de11 into main Nov 21, 2023
4 checks passed
@raphodn raphodn deleted the raphodn/price-location-relationship branch November 21, 2023 00:06
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 this pull request may close these issues.

Create a Location model
2 participants