Skip to content
Permalink
Browse files
fix(boolean-values): allow 0 and 1 as boolean values (DEV-251) (#131)
* allow 0 and 1 as boolean values

* add documentation

* remove complexity

* use f-string for error message
  • Loading branch information
irinaschubert committed Dec 2, 2021
1 parent 6a40fc6 commit fd58ad45b71163ecece1b86c5a1f88932196fc76
Showing with 7 additions and 8 deletions.
  1. +1 −1 docs/dsp-tools-xmlupload.md
  2. +6 −7 knora/dsplib/models/value.py
@@ -696,7 +696,7 @@ Attributes:

#### `<boolean>`

The `<boolean>` element must contain the string "true" or "false", or the numeral 1 or 0.
The `<boolean>` element must contain the string "true" or "false", or the numeral 1 (true) or 0 (false).

Attributes:

@@ -601,18 +601,17 @@ def __init__(self,
iri: Optional[str] = None,
ark_url: Optional[str] = None,
vark_url: Optional[str] = None):

if type(value) is bool:
self._value = value

elif type(value) is str:
if value.upper() == 'TRUE':
else:
if value == 1 or value.upper() == 'TRUE' or value == '1':
self._value = True
elif value.upper() == 'FALSE':
elif value == 0 or value.upper() == 'FALSE' or value == '0':
self._value = False
else:
raise BaseError("Invalid boolean format! " + str(value))
elif type(value) is int:
self._value = False if value == 0 else True
raise BaseError(f"ERROR Invalid boolean format {value}!")

super().__init__(iri=iri,
comment=comment,
permissions=permissions,

0 comments on commit fd58ad4

Please sign in to comment.