Robyn icon indicating copy to clipboard operation
Robyn copied to clipboard

View controllers don't have access to the global variables.

Open sansyrox opened this issue 1 year ago • 8 comments

Bug Description

Try creating a view and then accessing a global variable through that. It doesn't work.

Something like this doesn't work. Fix this.

db = DB()
def AsyncView():
    async def get():
        res = db(bla)
        return "Hello, world!"

Steps to Reproduce

No response

Your operating system

None

Your Python version (python --version)

None

Your Robyn version

None

Additional Info

No response

sansyrox avatar Mar 20 '23 09:03 sansyrox

Does this have any news? I am really interested in working with Views. Any idea if making the Instance on the View does make it work?

Noborita9 avatar Apr 01 '23 00:04 Noborita9

@Noborita9 , apologies for the late revert. This comment missed my eye.

Any idea if making the Instance on the View does make it work?

What do you mean by this?

sansyrox avatar Apr 09 '23 05:04 sansyrox

He probably means to create "db" from inside the view. But it doesn’t work either.

And functions that are not named by methods will raise an error iirc. Something along a wrong index value when nested functions are being collected.

andryyy avatar Apr 09 '23 10:04 andryyy

Perhaps it can be implemented with a decorator like @view_extension that can pass functions other than method handlers. These functions can carry globales and return them to method handlers or something like that.

andryyy avatar Apr 09 '23 10:04 andryyy

He probably means to create "db" from inside the view. But it doesn’t work either.

Yeah exactly that

Noborita9 avatar Apr 09 '23 14:04 Noborita9

I don't think that will work. I am using this library for this - https://github.com/sansyrox/nestd/blob/main/nestd/init.py#L35

We will have to change something around this line imo.

sansyrox avatar Apr 09 '23 14:04 sansyrox

Yes, that’s where it throw the error. I have had no time to investigate further. :(

andryyy avatar Apr 09 '23 15:04 andryyy

No worries. I will get around to it soon 😄

sansyrox avatar Apr 09 '23 22:04 sansyrox