Skip to content

Commit

Permalink
fix: use None instead of null as default value for optional fields (#138
Browse files Browse the repository at this point in the history
)

See #137 for what prompted this
  • Loading branch information
Rebecca Graber authored Oct 31, 2022
1 parent 8909df5 commit c1c24c7
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Change Log
Unreleased
----------

[3.0.1] - 2022-10-31
--------------------
Fixed
~~~~~
* Fix default value for optional fields from "null" to None

[3.0.0] - 2022-10-19
--------------------
* **Breaking change**: Removed (optional) field ``effort`` from ``CourseCatalogData.`` Nothing should be relying on this field as it is not used by Course Discovery in Publisher-enabled setups.
Expand Down
2 changes: 1 addition & 1 deletion openedx_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
more information about the project.
"""

__version__ = "3.0.0"
__version__ = "3.0.1"
2 changes: 1 addition & 1 deletion openedx_events/event_bus/avro/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _create_avro_field_definition(data_key, data_type, previously_seen_types,
" defined in custom_type_to_avro_type."
)
if default_is_none:
field["default"] = "null"
field["default"] = None
single_type = field["type"]
field["type"] = ["null", single_type]
return field
24 changes: 12 additions & 12 deletions openedx_events/event_bus/avro/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ def test_schema_for_types_with_defaults(self):
"fields": [
{"name": "test_data", "type":
{"name": "SimpleAttrsWithDefaults", "type": "record", "fields": [
{"name": "boolean_field", "type": ["null", "boolean"], "default": "null"},
{"name": "int_field", "type": ["null", "long"], "default": "null"},
{"name": "float_field", "type": ["null", "double"], "default": "null"},
{"name": "bytes_field", "type": ["null", "bytes"], "default": "null"},
{"name": "string_field", "type": ["null", "string"], "default": "null"},
{"name": "attrs_field", "default": "null",
{"name": "boolean_field", "type": ["null", "boolean"], "default": None},
{"name": "int_field", "type": ["null", "long"], "default": None},
{"name": "float_field", "type": ["null", "double"], "default": None},
{"name": "bytes_field", "type": ["null", "bytes"], "default": None},
{"name": "string_field", "type": ["null", "string"], "default": None},
{"name": "attrs_field", "default": None,
"type": ["null",
{"name": "SimpleAttrs", "type": "record", "fields": [
{"name": "boolean_field", "type": "boolean"},
Expand Down Expand Up @@ -201,12 +201,12 @@ def test_schema_for_types_with_nested_defaults(self):
'name': 'SimpleAttrsWithDefaults',
'type': 'record',
'fields': [
{'name': 'boolean_field', 'type': ['null', 'boolean'], 'default': 'null'},
{'name': 'int_field', 'type': ['null', 'long'], 'default': 'null'},
{'name': 'float_field', 'type': ['null', 'double'], 'default': 'null'},
{'name': 'bytes_field', 'type': ['null', 'bytes'], 'default': 'null'},
{'name': 'string_field', 'type': ['null', 'string'], 'default': 'null'},
{'name': 'attrs_field', 'default': 'null',
{'name': 'boolean_field', 'type': ['null', 'boolean'], 'default': None},
{'name': 'int_field', 'type': ['null', 'long'], 'default': None},
{'name': 'float_field', 'type': ['null', 'double'], 'default': None},
{'name': 'bytes_field', 'type': ['null', 'bytes'], 'default': None},
{'name': 'string_field', 'type': ['null', 'string'], 'default': None},
{'name': 'attrs_field', 'default': None,
'type': ['null', {
'name': 'SimpleAttrs',
'type': 'record',
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ django==3.2.16
# -r requirements/base.in
edx-opaque-keys[django]==2.3.0
# via -r requirements/base.in
fastavro==1.6.1
fastavro==1.7.0
# via -r requirements/base.in
pbr==5.10.0
# via stevedore
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ edx-lint==5.3.0
# via -r requirements/quality.txt
edx-opaque-keys[django]==2.3.0
# via -r requirements/quality.txt
fastavro==1.6.1
fastavro==1.7.0
# via -r requirements/quality.txt
filelock==3.8.0
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ edx-opaque-keys[django]==2.3.0
# via -r requirements/test.txt
edx-sphinx-theme==3.0.0
# via -r requirements/doc.in
fastavro==1.6.1
fastavro==1.7.0
# via -r requirements/test.txt
idna==3.4
# via requests
Expand Down
2 changes: 1 addition & 1 deletion requirements/quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ edx-lint==5.3.0
# via -r requirements/quality.in
edx-opaque-keys[django]==2.3.0
# via -r requirements/test.txt
fastavro==1.6.1
fastavro==1.7.0
# via -r requirements/test.txt
idna==3.4
# via requests
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ django==3.2.16
# -r requirements/base.txt
edx-opaque-keys[django]==2.3.0
# via -r requirements/base.txt
fastavro==1.6.1
fastavro==1.7.0
# via -r requirements/base.txt
iniconfig==1.1.1
# via pytest
Expand Down

0 comments on commit c1c24c7

Please sign in to comment.