Skip to content
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

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

Open
sansyrox opened this issue Mar 20, 2023 · 8 comments
Open

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

sansyrox opened this issue Mar 20, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@sansyrox
Copy link
Member

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 sansyrox added the bug Something isn't working label Mar 20, 2023
@Noborita9
Copy link
Contributor

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?

@sansyrox
Copy link
Member Author

sansyrox commented Apr 9, 2023

@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?

@andryyy
Copy link

andryyy commented Apr 9, 2023

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
Copy link

andryyy commented Apr 9, 2023

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.

@Noborita9
Copy link
Contributor

Noborita9 commented Apr 9, 2023

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

Yeah exactly that

@sansyrox
Copy link
Member Author

sansyrox commented Apr 9, 2023

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.

@andryyy
Copy link

andryyy commented Apr 9, 2023

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

@sansyrox
Copy link
Member Author

sansyrox commented Apr 9, 2023

No worries. I will get around to it soon 😄

@sansyrox sansyrox mentioned this issue Dec 29, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants