Hi
I’m following the Data Script documentation at Data Script
However, many of the code snippets does not work, such as
data.users = frappe.get_all("User")
which should actually use
frappe.db.get_all()
But I cannot understand / resolve what is wrong with
data.posts = frappe.make_get_request("https://jsonplaceholder.typicode.com/posts")
If I copy https://jsonplaceholder.typicode.com/posts into my browser’s URL bar, it does return the expected JSON. So the REST API is correct. Clearly there’s something wrong with frappe.make_get_request()
Can someone please help.
avc
February 9, 2025, 5:50pm
2
Hi @EugeneP :
It’s working for me …
Have you enabled server_script for your site?
bench set-config server_script_enabled 1
Hope this helps.
Hi @avc
Good to hear from you again
Yip, it’s been activated, otherwise I would not have been able to execute other methods such as getting the currency exchange rate and gold price from Yahoo Finance
from yahooquery import Ticker as yq
data.yf = yq("ZAR=X GC=F").summary_detail
avc
February 9, 2025, 6:43pm
4
Can you inspect the response on browser dev tools? Can you see fetched data there?
I cannot Save the Data Script.
In order to Save the script, I have to comment out the line where I call frappe.make_get_request.
So I cannot even test it.
How can I test it in DevTools when I click Save on the Data Script modal window?
avc
February 9, 2025, 7:08pm
7
AFAIK, import
is not allowed on this kind of scripts …
Which error get you on saving?
A red notification at the bottom right saying that there was an error while fetching data.
The YF data is returned correctly, so the import must be working.
Even if I remove all other code and only have the frappe.make_get_request I still cannot save the script.
avc
February 9, 2025, 8:04pm
9
peterg
February 10, 2025, 3:55am
10
There’s something odd going on with your installation. I just checked Frappe Build on my site (v15 latest) and got different results from you.
Both
data.users = frappe.get_all("User")
and
data.posts = frappe.make_get_request("https://jsonplaceholder.typicode.com/posts")
work fine for me.
Like @avc and Mr. Bean, I’m also very surprised that import statements are working for you. I didn’t think that was possible last time I checked.
EugeneP
February 10, 2025, 4:04am
11
Hi @peterg
Yip, something very strange…
Why would frappe.get_all
not work but frappe.db.get_all
does?
And frappe.make_get_request
not at all?
peterg
February 10, 2025, 4:11am
12
If I’m not mistaken, the builder develop
branch targets Frappe v16, not v15. I think that’s probably your issue. I haven’t been following it closely, but I know there are some big API changes coming in v16.
All the releases are from the master
branch. If you switch to that, I suspect it will start working for you.
peterg
February 13, 2025, 3:08am
13
I’d be curious to know if this was the issue. Let us know, @EugeneP !
EugeneP
February 13, 2025, 4:07am
14
I did not plan / contemplate changing the branch, but with you asking for such indirectly, here’s the outcome:
bench switch-to-branch master --upgrade builder
bench update --patch
bench restart
To ensure and confirm the Data Script executes afresh, I added the stock symbol for Google (GOOG) to the Yahoo FInance query.
data.meep = [{'c':'m'},{'c':'e'},{'c':'e'},{'c':'p'}]
data.users_gl = frappe.db.get_list("User")
data.users_ga = frappe.db.get_all("User", fields=['*'])
from yahooquery import Ticker as yq
data.yf = yq("ZAR=X GC=F GOOG").summary_detail
# data.rest = frappe.make_get_request("https://jsonplaceholder.typicode.com/posts")
As can be seen below, it did.
However, the moment I uncomment the final
frappe.make_get_request
I get an error when clicking the Save button at the bottom of the Data Script editor, stating that “There was an error while fetching page data”.
Also note that I cannot change the
frappe.db.get_list
to
frappe.get_list
without the same error message when clicking Save.
All I can say is : It’s bizarre.
peterg
February 13, 2025, 5:38am
15
Yeah, at this point I think it’s fair to say you’ve got a non-working installation. If you can reproduce the issue, it’d be worth posting to the repo.
peterg
February 13, 2025, 7:04am
16
One other thought: you’ve switched the branch, but it’s not clear here if the builder site has been recompiled. It might be necessary to run bench build
as well.
EugeneP
February 13, 2025, 7:56am
17
I ran
bench build
and it all succeeded. I then did
bench reload
and there is no change to the behaviour. The YF query still runs as previously and the 2 frappe invocations still cause an error.
peterg
February 13, 2025, 10:30am
18
Hmm…I just installed the builder develop
branch on my development instance to test.
Results as expected:
It definitely seems like your installation is borked in some way or another. If this is a builder bug, it’s not one I can reproduce.