feat: xblock skill verification event - #165
Conversation
|
Thanks for the pull request, @navinkarkera! Please note that it may take us up to several weeks or months to complete a review and merge your PR. Feel free to add as much of the following information to the ticket as you can:
All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here. Please let us know once your PR is ready for our review and all tests are green. |
ec33782 to
d3b4807
Compare
|
Hi @navinkarkera! Is this ready for review? CC: @mariajgrimaldi |
|
can we also add an instruction for testing? |
d28c3ee to
7fe2742
Compare
@mariajgrimaldi Below xblock mixin/openedx-filter pipeline is making use of this signal to send user feedback about tags for the xblock. It has testing instructions included.
After completing test instructions from any one MR above, add below snippet somewhere, for example in from openedx_events.learning.signals import XBLOCK_SKILL_VERIFIED
XBLOCK_SKILL_VERIFIED.connect(lambda **x: print(x))Verify some tags from the UI created in the MR. It will print something like below: The exact section making use of this event in mixin can be found here. I am not sure how we can manually test these events independently. |
7fe2742 to
3392538
Compare
|
Flagging this for you @mariajgrimaldi :) |
99d3b41 to
38da62a
Compare
|
@mariajgrimaldi Gentle reminder, this MR is blocking openedx/taxonomy-connector#135. Kindly review. |
|
@navinkarkera: thanks for the patience! I'll be reviewing this on Monday. |
| return deserializer(data) | ||
| elif data_type in PYTHON_TYPE_TO_AVRO_MAPPING: | ||
| return data | ||
| elif PYTHON_TYPE_TO_AVRO_MAPPING.get(data_type_origin) == "array": |
There was a problem hiding this comment.
Why don't you try 🤔:
| elif PYTHON_TYPE_TO_AVRO_MAPPING.get(data_type_origin) == "array": | |
| elif data_type_origin in PYTHON_TYPE_TO_AVRO_MAPPING.get(data_type_origin): |
Or this type checking is just for lists? Is there a reason that dicts shouldn't be checked?
There was a problem hiding this comment.
@mariajgrimaldi I have only implemented support for list/array as dicts might require more change.
There was a problem hiding this comment.
Alternatively, can we just do if data_type_origin == list? It seems odd to work backwards from the map.
There was a problem hiding this comment.
@rgraber Makes sense.
Just in case we want to support other array like python types like set, the current condition would not require any change.
I can still change it to data_type_origin == list if you think my statement does not make sense.
There was a problem hiding this comment.
I still think we should go with == list for clarity
| with self.assertRaises(TypeError): | ||
| deserializer.from_dict(initial_dict) |
There was a problem hiding this comment.
Handling nested lists (with annotation) support again introduces complexity and I did not implement it as it is not required as of now.
If we remove inner list type annotation, i.e. change the type to List[list] it works because the schema is becomes: {'name': 'list_input', 'type': {'type': 'array', 'items': 'array'}}
def test_deserialization_of_nested_list_works(self):
SIGNAL = create_simple_signal({"list_input": List[list]})
initial_dict = {"list_input": [[1, 3], [4, 5]]}
deserializer = AvroSignalDeserializer(SIGNAL)
data = deserializer.from_dict(initial_dict)
self.assertEqual(data, initial_dict)There was a problem hiding this comment.
Do we want List[list] to work? Doesn't that open us up to issues with something like [[Object, 'a'], [1, "bananas"]]?
There was a problem hiding this comment.
@rgraber Good point! I have updated it to allow only simple types like int, str, bool etc.
|
Don't forget to rebase with the main branch! |
38da62a to
dcda85d
Compare
navinkarkera
left a comment
There was a problem hiding this comment.
@mariajgrimaldi Replied to your queries inline and rebased with main.
| return deserializer(data) | ||
| elif data_type in PYTHON_TYPE_TO_AVRO_MAPPING: | ||
| return data | ||
| elif PYTHON_TYPE_TO_AVRO_MAPPING.get(data_type_origin) == "array": |
There was a problem hiding this comment.
@mariajgrimaldi I have only implemented support for list/array as dicts might require more change.
| with self.assertRaises(TypeError): | ||
| deserializer.from_dict(initial_dict) |
There was a problem hiding this comment.
Handling nested lists (with annotation) support again introduces complexity and I did not implement it as it is not required as of now.
If we remove inner list type annotation, i.e. change the type to List[list] it works because the schema is becomes: {'name': 'list_input', 'type': {'type': 'array', 'items': 'array'}}
def test_deserialization_of_nested_list_works(self):
SIGNAL = create_simple_signal({"list_input": List[list]})
initial_dict = {"list_input": [[1, 3], [4, 5]]}
deserializer = AvroSignalDeserializer(SIGNAL)
data = deserializer.from_dict(initial_dict)
self.assertEqual(data, initial_dict)|
Hello there folks! @robrap @rgraber @timmc-edx. We're introducing these changes to the library, and I wanted to ensure you're OK with them. Please let us know! 😋 |
rgraber
left a comment
There was a problem hiding this comment.
Couple questions. In general, I think more comments about what get_args and get_origin are expected to return would make it easier to follow.
| return deserializer(data) | ||
| elif data_type in PYTHON_TYPE_TO_AVRO_MAPPING: | ||
| return data | ||
| elif PYTHON_TYPE_TO_AVRO_MAPPING.get(data_type_origin) == "array": |
There was a problem hiding this comment.
Alternatively, can we just do if data_type_origin == list? It seems odd to work backwards from the map.
| raise TypeError( | ||
| "List without annotation type is not supported. The argument should be a type, for eg., List[int]" | ||
| ) | ||
| if arg_data_type[0] in PYTHON_TYPE_TO_AVRO_MAPPING: |
There was a problem hiding this comment.
I think this will break on List[CourseKey] (or other custom-serialized class). That's ok but we should be very clear in exactly how much support we have for array types.
There was a problem hiding this comment.
As I mentioned in one of replies above, I have updated the code to only support basic types inside lists and it will raise meaningful error if unsupported type is passed.
| with self.assertRaises(TypeError): | ||
| deserializer.from_dict(initial_dict) |
There was a problem hiding this comment.
Do we want List[list] to work? Doesn't that open us up to issues with something like [[Object, 'a'], [1, "bananas"]]?
8a33abb to
0009eda
Compare
|
@mariajgrimaldi @rgraber Gentle reminder. Let me know if changes are required, else we should be good to merge. |
|
we would like your approval here @rgraber :) thanks! |
0009eda to
b9c11a2
Compare
rgraber
left a comment
There was a problem hiding this comment.
Couple more things, but overall looks great!
| return deserializer(data) | ||
| elif data_type in PYTHON_TYPE_TO_AVRO_MAPPING: | ||
| return data | ||
| elif PYTHON_TYPE_TO_AVRO_MAPPING.get(data_type_origin) == "array": |
There was a problem hiding this comment.
I still think we should go with == list for clarity
| with self.assertRaises(Exception): | ||
| schema_from_signal(DICT_SIGNAL) | ||
|
|
||
| def test_throw_exception_to_list_or_dict_types_without_annotation(self): |
There was a problem hiding this comment.
Isn't this just a duplicate of the above test? Did you mean to rename?
There was a problem hiding this comment.
@rgraber Thanks for catching it, I indeed meant to rename the function.
Update: Actually it was helping in code coverage, so I have updated the test to include a signal with List type.
Adds data class and event to send skill verification data for an XBlock. feat: add support for array avro types chore: add changelog docs: update signals docs to be more generic test: fix code coverage refactor: add docstrings
5f62d9f to
6b6b646
Compare
|
@navinkarkera 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
|
@navinkarkera: the new release is out! |
|
@mariajgrimaldi @rgraber Thank you! |
This reverts commit 26a8dd5.
Adds data class and event to send skill verification data for an XBlock.
Updates avro serialization & de serialization just enough to support array types.
Description: The idea is that users will verify the tags/skills associated to an XBlock. We want to send this data via openedx-event signals to course-discovery and update the relevant tables.
JIRA:
Private-ref: BB-6885Dependencies: #143
Original MR: open-craft#1
Merge checklist:
Post merge:
finished.
Author concerns: Only support for array type is added as it is required for this event.