starlette-session icon indicating copy to clipboard operation
starlette-session copied to clipboard

Backend Memcache Set -- argument set is set to None

Open Nootaku opened this issue 1 year ago • 0 comments

Hey,

It seems there might be a little error in the configuration of the MemcacheSessionBackend object.

When trying the code as displayed in the examples I get the following error:

raise MemcacheIllegalInputError(
pymemcache.exceptions.MemcacheIllegalInputError: expire must be integer, got bad value: None

After looking at the documentation for pymemcache, it seems that the exp argument should be an Integer indeed (default at 0).

So I would recommend changing the MemcacheSessionBackend from:

async def set(
        self, key: str, value: dict, exp: Optional[int] = None, **kwargs: dict
    ) -> Optional[str]:
        return self.memcache.set(key, value, expire=exp, **kwargs)

to:

async def set(
        self, key: str, value: dict, exp: Optional[int] = None, **kwargs: dict
    ) -> Optional[str]:
        if exp is None:
            return self.memcache.set(key, value, expire=0, **kwargs)
        else:
            return self.memcache.set(key, value, expire=exp, **kwargs)

Nootaku avatar Mar 14 '23 10:03 Nootaku