fix(images): return correct image path after generation (a classic SQLAlchemy "detached instance" bug by making sure to access ORM attributes while the session is still open).

-update Pixabay API to default to per_page3
This commit is contained in:
sudipnext 2025-07-29 11:31:43 +05:45
parent eb1c2dd143
commit 71ff6e6adf
2 changed files with 3 additions and 2 deletions

View file

@ -24,8 +24,9 @@ async def generate_image(prompt: str):
with get_sql_session() as sql_session:
sql_session.add(image)
sql_session.commit()
image_path = image.path
return image.path
return image_path
@IMAGES_ROUTER.get("/generated", response_model=List[ImageAsset])

View file

@ -123,7 +123,7 @@ class ImageGenerationService:
async def get_image_from_pixabay(self, prompt: str) -> str:
async with aiohttp.ClientSession() as session:
response = await session.get(
f"https://pixabay.com/api/?key={get_pixabay_api_key_env()}&q={prompt}&image_type=photo&per_page=1"
f"https://pixabay.com/api/?key={get_pixabay_api_key_env()}&q={prompt}&image_type=photo&per_page=3"
)
data = await response.json()
image_url = data["hits"][0]["largeImageURL"]