Coder Social home page Coder Social logo

Issues with sessions about lapis HOT 13 OPEN

catwell avatar catwell commented on August 22, 2024
Issues with sessions

from lapis.

Comments (13)

leafo avatar leafo commented on August 22, 2024

I'm aware of the session removal issue. I've been using the false assignment workaround in my sites, but I think it's time to make it a little bit more proper and detect nil assignments.

As for __index being a function, I've never seen that happen before, but I see no issue with adding a check there.

from lapis.

catwell avatar catwell commented on August 22, 2024

Thank you. Regarding __index being a function I will try to make a simple test case that exhibits the problem this weekend.

from lapis.

catwell avatar catwell commented on August 22, 2024

Actually the 2nd workaround does not work, it did only because I had commented out code (using false instead of nil does). And I couldn't reproduce __index being a function so disregard that for now.

from lapis.

iandyh avatar iandyh commented on August 22, 2024

@leafo I am currently experiencing the __index being a function issue. Completely have no idea why this would happen. I have dig around but found no solutions.

So I use cookies instead now.

from lapis.

catwell avatar catwell commented on August 22, 2024

I have had a look and here's where I think the issue with __index being a function comes from. Well, that's if I have understood all this meta-magic correctly :)

OK, so the session is an auto_table. An auto_table is a table with a __index metamethod by default (so "__index is a function").

The reason this bug does not happen all the time is that actually the __index metamethod is a closure, and when it is called it replaces itself with the result of the enclosed fn (a table). So if you access a field in the session before trying to iterate __index it works, but not if you don't.

from lapis.

leafo avatar leafo commented on August 22, 2024

Ah good catch, thanks for looking into it.

from lapis.

kotedo avatar kotedo commented on August 22, 2024

Question: Has the session issue been fixed? I am using the latest github checked out version and I am still having the aforementioned session issues.

Thank you!

from lapis.

leafo avatar leafo commented on August 22, 2024

Still haven't changed the delete issue. The __index being a function has been fixed.

from lapis.

kotedo avatar kotedo commented on August 22, 2024

Right, that's what I noticed. It renders sessions almost unusable ... and I was hoping to use Lapis for an important site that requires sessions.

from lapis.

leafo avatar leafo commented on August 22, 2024

I wouldn't say they're unusable. Set to false if you want to delete. I'll try to get patch out asap.

from lapis.

leafo avatar leafo commented on August 22, 2024

So I've taken care of the assigning nil issue, but I'm not satisfied with the overall result. You will still run into trouble if you have a table serialized into the session and you modify it, the code won't be able to detect the change in the child object. I'm wondering if I should just change the interface completely, have some method that marks the session as dirty and forces it to be written, or write something that wraps the objects that come from the session so I can tell if any nested object is changed.

from lapis.

catwell avatar catwell commented on August 22, 2024

That last solution looks right. What can be stored in sessions exactly? Userdata, functions? If neither can then just adding metatables to tables stored in sessions so that they propagate the "modified" state upwards sounds good.

from lapis.

leafo avatar leafo commented on August 22, 2024

Anything that can be serialized by lua cjson. I should mention that somewhere.

from lapis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.