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

Issue with importing uuid class? #22

Closed
psychohamster opened this issue Apr 7, 2020 · 3 comments
Closed

Issue with importing uuid class? #22

psychohamster opened this issue Apr 7, 2020 · 3 comments

Comments

@psychohamster
Copy link

psychohamster commented Apr 7, 2020

Hello,
I've had a monthly batch process that I've been using for about a year based on this sublime plugin which has been working great. It uses some UDFs defined in the .rbql_init_source.py file that require the uuid functions. So i've had 'import uuid' at the top of the init file working great for ages. A few weeks ago I started trying to run the process (skipped Feb this year, so I think my last successful run was with 1.5.0) and now it acts like the import uuid statement no longer works, as I get 'undefined global uuid' error when running my function within the query.
At first, I assumed it was something wonky with the sublime embedded python and started rolling back versions of ST3 to no avail. Even confirmed / recompiled the 3.3.6 pyo for the uuid class, etc.
After no luck there, I tried running the same process using VSCode and its corresponding rbql plugin, with the same result. So, I'm guessing some sort of weird conflict has come up with uuid, since I can import sys and use functions there with no problem.

I confirmed I can exec the functions from the python cli on the system level.

Steps for simple repro:

Install any recent version of ST3 and install Rainbow_CSV from package control
.rbql_init_source.py:

import uuid
import sys

def bob():
	return sys.version

def joe():
	return uuid.uuid4()

Open up a csv file in ST3 and run the following:
update set a1 = joe()

query execution, Error at line 1, details: global name 'uuid' is not defined

Now try this:
update set a1 = bob()
File executes and replaces with the expected embedded python version string

I'm going to downgrade to 1.5.0 and see if comes back, but figured I'd post here too in case anyone has run into this and has a quick solution I'm missing.

[updated] - downgraded the st3 package to 1.5.0 by replacing the folder under packages and now it works again.

Thanks!

@mechatroner
Copy link
Owner

Hello @psychohamster,
Thank you very much for this bug report!
I spent half an hour in disbelief debugging this issue, turns out the root cause of the problem is this: https://stackoverflow.com/questions/12505047/why-doesnt-an-import-in-an-exec-in-a-function-work - "import" does not work in "exec()" functions properly. The reason why "sys" module works is because it is imported by rbql itself. Starting from version 1.6.0 I switched to an updated rbql engine which instead of generating a temporary python module uses exec function. I think I had some tests with "import" statements in ".rbql_init_source.py", but they didn't fail because if you use imported modules without wrapping them into a function call - it works, e.g. this will work too: update set a1 = uuid.uuid4(). I will try to fix this problem ASAP.

mechatroner pushed a commit to mechatroner/RBQL that referenced this issue Apr 9, 2020
…tatements would work correctly inside ~/.rbql_init_source.py
mechatroner pushed a commit to mechatroner/RBQL that referenced this issue Apr 9, 2020
@psychohamster
Copy link
Author

Glad I wasn't going crazy and missing something obvious! Thank you very much for tracking that down so fast.

@mechatroner
Copy link
Owner

I've published a new version with import fix: 1.7.1. Please let me know if you find any other issues with the plugin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants