-
Notifications
You must be signed in to change notification settings - Fork 25
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
sqlalchemy object caching issue #83
Comments
Hello, I think objects like sqlalchemy orm is a good use case for caching, if it possible to pickle somehow. |
Hi @dotX12 , the release is ready to upload on pypi but I can't reproduce this issue. ) I tried with simple examples but with different types of sqlalchemy objects and can't get an error like you have. import asyncio
from cashews import cache
cache.setup("redis://")
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import declarative_base, sessionmaker
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
from sqlalchemy.ext.asyncio import create_async_engine
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
fullname = Column(String)
nickname = Column(String)
@cache(ttl="1m", key="user:{id}")
async def get_user(session, id):
user = await session.get(User, id)
return user
async def main():
engine = create_async_engine('sqlite+aiosqlite:///:memory:', echo=False)
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
async_session = sessionmaker(
engine, expire_on_commit=False, class_=AsyncSession
)
async with async_session() as session:
async with session.begin():
session.add_all(
[
User(name="test", id=11, fullname="10 th", nickname="test10"),
]
)
user = await get_user(session, 11)
print(user.fullname)
asyncio.run(main())
|
Hi, I'm not at home right now, I'll test it tomorrow evening, thanks! |
OK but you can test it only on master branch - release postponed. It will be nice to have and example of code with this bug |
@Krukov, indeed, your example doesn't cause this problem. |
@dotX12 Hello |
@Krukov |
Don't worry, it is OK. Have a good weekend! |
Hi @dotX12 . Do you have any updates? ) |
Hello, now I sit down to reproduce the bug, I think tomorrow or after tomorrow I will send it! |
@Krukov, solved :) |
Great, than I will release new version soon |
released with 4.7.1 |
Greetings! I ran into sqlalchemy object caching issues. From time to time I get errors like this:
I found the answer that such objects should be serialized and deserialized differently:
https://docs.sqlalchemy.org/en/14/core/serializer.html
Tell me how good / bad idea it is to cache alchemy objects, and not the endpoint itself.
If this is not bad, what can you say about adding functionality that could fix this error?
The text was updated successfully, but these errors were encountered: