Skip to content

bug: Error compiling Dataform if explicit variable assignment is used when calling javascript function #124

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

Open
MaximumV opened this issue Mar 18, 2025 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@MaximumV
Copy link

Describe the bug
I run dataform compile --timeout 60000
or just click "show vertical split" in vscode interface

Expected behavior
Compilation window reference other models in list, not current one
Checked affiliate_id field, which shows like mistake in all models - it's ok and is compiled/run in web dataform

Screenshots

Image

Environment:

  • WSL2/ Ubuntu-24.04
  • Dataform cli version 2.9.0
  • Version of the extension 0.10.9
  • ...
@ashish10alex
Copy link
Owner

ashish10alex commented Mar 18, 2025

Hi @MaximumV , thanks for raising the issue. Can you please let me know what this affiliate_id is ? Is that a variable or column or something else. Could you be able to provide be minimal code that has this affiliate_id in it so that I can reproduce the issue locally.

edit: you can also use this repository to reproduce the error. Make sure you sue the dataform_v2 branch, which is what you are using.

@MaximumV
Copy link
Author

Hi @ashish10alex, and thank you for the prompt reply!
I realized what the problem is
affiliate_id is column name

Here the example, I hope you will be able to help, I commented the js function and compile mistake vanished:

select
  f.Affiliate              as affiliate_name
 ,f.Affiliate_ID           as affiliate_id
 ,f.country                as country
 -- ,${h.create_financeads_key_for_reports(
 --   affiliate_id  ="f.Affiliate_ID"
 --   ,country      ="f.country")
 -- }                                       as financeads_key
from    united as f

Where h.js is includes with:

function create_financeads_key_for_reports(affiliate_id,country){
   return `
   trim(array_to_string(
       [
           safe_cast(${affiliate_id} as string)
           ,${country}
       ]
       , '-', 'null'
   ))
   `
}

this compiled on web:
   trim(array_to_string(
       [
           safe_cast(f.Affiliate_ID as string)
           ,f.country
       ]
       , '-', 'null'
   )) as financeads_key

P.S. You are doing great extension! Thank you for youtube video, liked

@ashish10alex
Copy link
Owner

Hi @MaximumV , thanks for providing the example, that was helpful to isolate the error. From my testing, It seems like the issue is with the Dataform cli than the extension as dataform compile on terminal throws the same error. So, the error seems to go away when you remove explicit variable assignment when using javascript function. I will be creating an issue in the main Dataform repository about this. As you said, I tried this in the Dataform GCP UI and it compiles without any error. My guess is it has something to do with the way javascript is being parsed. Simplest working example

config {
  type: 'view'
}

js {
  function someOperation(var1){
   return `"${var1}"`
}

}

select 
${someOperation('hello')} as some_column           -- works
--${someOperation(var1='hello') } as some_column   -- does not work

@ashish10alex ashish10alex added bug Something isn't working help wanted Extra attention is needed labels Mar 20, 2025
@ashish10alex ashish10alex changed the title bug: Error compiling Dataform bug: Error compiling Dataform if explicit variable assignment is used when calling javascript function Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants