Skip to content

Commit 7fa0a8b

Browse files
committed
[Python] Remove one-ofs and default values (#2670)
## Changes Remove one-ofs and default values until they become a part of the JSON schema. ## Why It allows full generating Python code from JSON schema without overrides and removes cases where bundle configuration can't be created as a Python object.
1 parent 5a46666 commit 7fa0a8b

File tree

7 files changed

+10
-93
lines changed

7 files changed

+10
-93
lines changed

experimental/python/databricks/bundles/jobs/_models/cron_schedule.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ class CronSchedule:
1919
A Cron expression using Quartz syntax that describes the schedule for a job. See [Cron Trigger](http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html) for details. This field is required.
2020
"""
2121

22-
pause_status: VariableOrOptional[PauseStatus] = None
22+
timezone_id: VariableOr[str]
2323
"""
24-
Indicate whether this schedule is paused or not.
24+
A Java timezone ID. The schedule for a job is resolved with respect to this timezone. See [Java TimeZone](https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html) for details. This field is required.
2525
"""
2626

27-
timezone_id: VariableOr[str] = "UTC"
27+
pause_status: VariableOrOptional[PauseStatus] = None
2828
"""
29-
A Java timezone ID. The schedule for a job is resolved with respect to this timezone. See [Java TimeZone](https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html) for details. This field is required.
29+
Indicate whether this schedule is paused or not.
3030
"""
3131

3232
@classmethod
@@ -45,14 +45,14 @@ class CronScheduleDict(TypedDict, total=False):
4545
A Cron expression using Quartz syntax that describes the schedule for a job. See [Cron Trigger](http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html) for details. This field is required.
4646
"""
4747

48-
pause_status: VariableOrOptional[PauseStatusParam]
48+
timezone_id: VariableOr[str]
4949
"""
50-
Indicate whether this schedule is paused or not.
50+
A Java timezone ID. The schedule for a job is resolved with respect to this timezone. See [Java TimeZone](https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html) for details. This field is required.
5151
"""
5252

53-
timezone_id: VariableOr[str]
53+
pause_status: VariableOrOptional[PauseStatusParam]
5454
"""
55-
A Java timezone ID. The schedule for a job is resolved with respect to this timezone. See [Java TimeZone](https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html) for details. This field is required.
55+
Indicate whether this schedule is paused or not.
5656
"""
5757

5858

experimental/python/databricks/bundles/jobs/_models/job_permission.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@ class JobPermission:
2525

2626
user_name: VariableOrOptional[str] = None
2727

28-
def __post_init__(self):
29-
union_fields = [
30-
self.user_name,
31-
self.service_principal_name,
32-
self.group_name,
33-
]
34-
35-
if sum(f is not None for f in union_fields) != 1:
36-
raise ValueError(
37-
"JobPermission must specify exactly one of 'user_name', 'service_principal_name', 'group_name'"
38-
)
39-
4028
@classmethod
4129
def from_dict(cls, value: "JobPermissionDict") -> "Self":
4230
return _transform(cls, value)

experimental/python/databricks/bundles/jobs/_models/job_run_as.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ class JobRunAs:
2727
The email of an active workspace user. Non-admin users can only set this field to their own email.
2828
"""
2929

30-
def __post_init__(self):
31-
union_fields = [
32-
self.user_name,
33-
self.service_principal_name,
34-
]
35-
36-
if sum(f is not None for f in union_fields) != 1:
37-
raise ValueError(
38-
"JobRunAs must specify exactly one of 'user_name', 'service_principal_name'"
39-
)
40-
4130
@classmethod
4231
def from_dict(cls, value: "JobRunAsDict") -> "Self":
4332
return _transform(cls, value)

experimental/python/databricks/bundles/jobs/_models/task.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,6 @@ class Task:
269269
A collection of system notification IDs to notify when runs of this task begin or complete. The default behavior is to not send any system notifications.
270270
"""
271271

272-
def __post_init__(self):
273-
union_fields = [
274-
self.new_cluster,
275-
self.job_cluster_key,
276-
self.environment_key,
277-
self.existing_cluster_id,
278-
]
279-
280-
if sum(f is not None for f in union_fields) > 1:
281-
raise ValueError(
282-
"Only one of 'new_cluster', 'job_cluster_key', 'environment_key', 'existing_cluster_id' can be specified in Task"
283-
)
284-
285272
@classmethod
286273
def from_dict(cls, value: "TaskDict") -> "Self":
287274
return _transform(cls, value)

experimental/python/databricks/bundles/jobs/_models/trigger_settings.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ class TriggerSettings:
4646
:meta private: [EXPERIMENTAL]
4747
"""
4848

49-
def __post_init__(self):
50-
union_fields = [
51-
self.file_arrival,
52-
self.periodic,
53-
self.table_update,
54-
]
55-
56-
if sum(f is not None for f in union_fields) != 1:
57-
raise ValueError(
58-
"TriggerSettings must specify exactly one of 'file_arrival', 'periodic', 'table_update'"
59-
)
60-
6149
@classmethod
6250
def from_dict(cls, value: "TriggerSettingsDict") -> "Self":
6351
return _transform(cls, value)

experimental/python/databricks_tests/core/test_transform.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,14 @@ def test_cron_schedule():
233233
CronSchedule,
234234
{
235235
"quartz_cron_expression": "0 0 0 * * ?",
236+
"timezone_id": "UTC",
236237
"pause_status": Variable(path="var.pause_status", type=str),
237238
},
238239
)
239240

240241
assert cron_schedule == CronSchedule(
241242
quartz_cron_expression="0 0 0 * * ?",
243+
timezone_id="UTC",
242244
pause_status=Variable(path="var.pause_status", type=PauseStatus),
243245
)
244246

experimental/python/databricks_tests/jobs/test_permission.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)