Skip to content

Commit ede3396

Browse files
authored
[SCHEMATIC-277] fix bug where columnType mistaken conflicts with no type validation type (#1635)
* fix bug where columnType mistaken conflicts with no type validaiton rules * rearange logic * remove unneeded comments
1 parent aecb158 commit ede3396

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

schematic/schemas/create_json_schema.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -281,30 +281,28 @@ def _get_validation_rule_based_fields(
281281
# Schematic will use the implicit type if the explicit type isn't specified for now,
282282
# but this behavior is deprecated and will be removed in the future by SCHEMATIC-326
283283
implicit_js_type = get_js_type_from_inputted_rules(validation_rules)
284-
# If there is an explicit type set...
285-
if explicit_js_type:
286-
# and the implicit type conflicts with the explicit type, then an exception is raised
287-
if explicit_js_type != implicit_js_type:
288-
msg = (
289-
f"Property: '{name}', has explicit type: '{explicit_js_type}' "
290-
f"that conflicts with the implicit type: '{implicit_js_type}' "
291-
f"derived from its validation rules: {validation_rules}"
292-
)
293-
raise ValueError(msg)
294-
# If there is no explicit type...
295-
else:
296-
# and there is an implicit type...
297-
if implicit_js_type:
298-
# then the implicit type is used...
299-
js_type = implicit_js_type
300-
# and a warning is raised since this behavior is deprecated
301-
msg = (
302-
f"No explicit type set for property: '{name}', "
303-
"using validation rules to set the type. "
304-
"Using validation rules to set type is deprecated. "
305-
"You should set the columnType for this property in your data model."
306-
)
307-
warnings.warn(msg)
284+
# If there is an explicit and implicit type set and the implicit type conflicts with the
285+
# explicit type, then an exception is raised
286+
if (
287+
explicit_js_type
288+
and implicit_js_type
289+
and explicit_js_type != implicit_js_type
290+
):
291+
msg = (
292+
f"Property: '{name}', has explicit type: '{explicit_js_type}' "
293+
f"that conflicts with the implicit type: '{implicit_js_type}' "
294+
f"derived from its validation rules: {validation_rules}"
295+
)
296+
raise ValueError(msg)
297+
if implicit_js_type:
298+
js_type = implicit_js_type
299+
msg = (
300+
f"No explicit type set for property: '{name}', "
301+
"using validation rules to set the type. "
302+
"Using validation rules to set type is deprecated. "
303+
"You should set the columnType for this property in your data model."
304+
)
305+
warnings.warn(msg)
308306

309307
if ValidationRuleName.URL in validation_rule_names:
310308
js_format = JSONSchemaFormat.URI

tests/unit/test_create_json_schema.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ def test_get_validation_rule_based_fields_no_explicit_type(
283283
None,
284284
None,
285285
),
286+
(
287+
["list"],
288+
JSONSchemaType.STRING,
289+
JSONSchemaType.STRING,
290+
True,
291+
None,
292+
None,
293+
None,
294+
None,
295+
),
286296
(
287297
["inRange 50 100"],
288298
JSONSchemaType.NUMBER,
@@ -324,7 +334,7 @@ def test_get_validation_rule_based_fields_no_explicit_type(
324334
JSONSchemaFormat.URI,
325335
),
326336
],
327-
ids=["No rules", "String", "InRange", "Regex", "Date", "URL"],
337+
ids=["No rules", "String", "List string", "InRange", "Regex", "Date", "URL"],
328338
)
329339
def test_get_validation_rule_based_fields_with_explicit_type(
330340
validation_rules: list[str],

0 commit comments

Comments
 (0)