Skip to content

Commit ff8eb54

Browse files
committed
enforce dataspace as required
1 parent 3dee1f7 commit ff8eb54

3 files changed

Lines changed: 33 additions & 33 deletions

File tree

src/datacustomcode/io/reader/query_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(
8585
self.spark = spark
8686
credentials = Credentials.from_available(profile=credentials_profile)
8787

88-
if dataspace is not None:
88+
if dataspace is not None and dataspace != "default":
8989
self._conn = SalesforceCDPConnection(
9090
credentials.login_url,
9191
credentials.username,

src/datacustomcode/io/writer/print.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ def __init__(
3939
self.spark, credentials_profile, dataspace=dataspace
4040
)
4141
else:
42-
self.reader = QueryAPIDataCloudReader(
43-
self.spark, credentials_profile
44-
)
42+
self.reader = QueryAPIDataCloudReader(self.spark, credentials_profile)
4543
else:
4644
self.reader = reader
4745

src/datacustomcode/run.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,39 @@ def run_entrypoint(
3838
profile: The credentials profile to use.
3939
"""
4040
add_py_folder(entrypoint)
41-
42-
# Read dataspace from config.json if it exists
41+
42+
# Read dataspace from config.json (required)
4343
entrypoint_dir = os.path.dirname(entrypoint)
4444
config_json_path = os.path.join(entrypoint_dir, "config.json")
45-
if os.path.exists(config_json_path):
46-
try:
47-
with open(config_json_path, "r") as f:
48-
config_json = json.load(f)
49-
dataspace = config_json.get("dataspace")
50-
if dataspace:
51-
# Add dataspace to reader config options
52-
if (
53-
config.reader_config
54-
and hasattr(config.reader_config, "options")
55-
):
56-
config.reader_config.options["dataspace"] = dataspace
57-
# Add dataspace to writer config options (for PrintDataCloudWriter)
58-
if (
59-
config.writer_config
60-
and hasattr(config.writer_config, "options")
61-
):
62-
config.writer_config.options["dataspace"] = dataspace
63-
except json.JSONDecodeError as err:
64-
raise ValueError(
65-
f"config.json at {config_json_path} is not valid JSON"
66-
) from err
67-
except FileNotFoundError as err:
68-
raise FileNotFoundError(
69-
f"config.json not found at {config_json_path}"
70-
) from err
71-
45+
46+
if not os.path.exists(config_json_path):
47+
raise FileNotFoundError(
48+
f"config.json not found at {config_json_path}. config.json is required."
49+
)
50+
51+
try:
52+
with open(config_json_path, "r") as f:
53+
config_json = json.load(f)
54+
except json.JSONDecodeError as err:
55+
raise ValueError(
56+
f"config.json at {config_json_path} is not valid JSON"
57+
) from err
58+
59+
# Require dataspace to be present in config.json
60+
dataspace = config_json.get("dataspace")
61+
if not dataspace:
62+
raise ValueError(
63+
f"config.json at {config_json_path} is missing required field 'dataspace'. "
64+
f"Please ensure config.json contains a 'dataspace' field."
65+
)
66+
67+
# Add dataspace to reader config options
68+
if config.reader_config and hasattr(config.reader_config, "options"):
69+
config.reader_config.options["dataspace"] = dataspace
70+
# Add dataspace to writer config options (for PrintDataCloudWriter)
71+
if config.writer_config and hasattr(config.writer_config, "options"):
72+
config.writer_config.options["dataspace"] = dataspace
73+
7274
if profile != "default":
7375
if config.reader_config and hasattr(config.reader_config, "options"):
7476
config.reader_config.options["credentials_profile"] = profile

0 commit comments

Comments
 (0)