Skip to content

Commit d69222c

Browse files
ovrigorlukanin
andauthored
fix: Throw a user-friendly error on an empty cube.py file (#9550)
Co-authored-by: Igor Lukanin <[email protected]>
1 parent 583e6dd commit d69222c

File tree

1 file changed

+12
-2
lines changed
  • packages/cubejs-backend-native/src/python

1 file changed

+12
-2
lines changed

packages/cubejs-backend-native/src/python/entry.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::python::neon_py::*;
44
use crate::python::python_model::CubePythonModel;
55
use crate::python::runtime::py_runtime_init;
66
use neon::prelude::*;
7+
use pyo3::exceptions::PyException;
78
use pyo3::prelude::*;
89
use pyo3::types::{PyDict, PyFunction, PyList, PyString, PyTuple};
910
use std::path::Path;
@@ -45,8 +46,15 @@ fn python_load_config(mut cx: FunctionContext) -> JsResult<JsPromise> {
4546
let settings_py = if config_module.hasattr("config")? {
4647
config_module.getattr("config")?
4748
} else {
48-
// backward compatibility
49-
config_module.getattr("settings")?
49+
// backward compatibility, was used in private preview, not as Public API
50+
// TODO: Remove after 1.4
51+
if config_module.hasattr("settings")? {
52+
config_module.getattr("settings")?
53+
} else {
54+
return Err(PyErr::new::<PyException, String>(
55+
"`cube.py` configuration file must define the 'config' attribute. Did you forget to add the `from cube import config` import?".to_string(),
56+
));
57+
}
5058
};
5159

5260
let mut cube_conf = CubeConfigPy::new();
@@ -119,6 +127,8 @@ fn python_load_model(mut cx: FunctionContext) -> JsResult<JsPromise> {
119127
);
120128
}
121129
} else {
130+
// backward compatibility, was used in private preview, not as Public API
131+
// TODO: Remove after 1.4
122132
let inspect_module = py.import("inspect")?;
123133
let args = (model_module, inspect_module.getattr("isfunction")?);
124134
let functions_with_names = inspect_module

0 commit comments

Comments
 (0)