-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring parse_message() #106
Changes from 7 commits
6d1d357
2aef392
350e892
5229b1a
08662e0
243c4c6
7f6954f
8e6f491
5505b4c
483a970
58e3979
932e23c
238710c
75cc530
1d794ca
3eb9861
3c7b942
a2c79e3
542e3bf
aa49ec8
66a6537
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from typing import Union, List, Dict | ||
from typing import Union, List, Dict, Any | ||
import os | ||
import tempfile | ||
|
||
|
@@ -27,3 +27,18 @@ def process(self, audio: schemas.Message) -> Dict[str, Union[str, List[int]]]: | |
finally: | ||
os.remove(temp_file_name) | ||
return {"hash_value": hash_value} | ||
|
||
@classmethod | ||
def validate_input(cls, data: Dict) -> None: | ||
""" | ||
Validate input data. Must be implemented by all child "Model" classes. | ||
""" | ||
pass | ||
|
||
|
||
@classmethod | ||
def parse_input_message(cls, data: Dict) -> Any: | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we do nothing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edit: ah I see what the issue is after reading your Jira message - I think we should talk through how to not just stub all these on our next ML call, but in the meantime I think looking at what we typically unit-test for, for each model, and just doing type-checking based on the types of responses we're testing for would be appropriate. |
||
Validate input data. Must be implemented by all child "Model" classes. | ||
""" | ||
return None |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from typing import Dict, Any | ||
import os | ||
import json | ||
from lib.logger import logger | ||
|
@@ -74,4 +75,27 @@ def process(self, message: Message) -> ClassyCatSchemaResponse: | |
return result | ||
except Exception as e: | ||
logger.error(f"Error looking up schema name {schema_name}: {e}") | ||
raise PrestoBaseException(f"Error looking up schema name {schema_name}", 500) from e | ||
raise PrestoBaseException(f"Error looking up schema name {schema_name}", 500) from e | ||
|
||
|
||
@classmethod | ||
def validate_input(cls, data: Dict) -> None: | ||
""" | ||
Validate input data. Must be implemented by all child "Model" classes. | ||
""" | ||
if "schema_name" not in data["parameters"] or data["parameters"]["schema_name"] == "": | ||
raise PrestoBaseException("schema_name is required as input to schema look up", 422) | ||
|
||
@classmethod | ||
def parse_input_message(cls, data: Dict) -> Any: | ||
""" | ||
Parse input into appropriate response instances. | ||
""" | ||
event_type = data['parameters']['event_type'] | ||
result_data = data.get('result', {}) | ||
|
||
if event_type == 'schema_lookup': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like this needs to check that either the schema_id or schema_name are not empty? It looks like ClassyCatSchemaResponse considers schema_id as optional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the class specific validator checks that those fields exist, look at however this function as implemented before only searches by name, not both name and id. maybe we can file a ticket for that if it's necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought there was already a function for lookup by schema name and a separate one for id? (I just wasn't sure which this was) |
||
return ClassyCatSchemaResponse(**result_data) | ||
else: | ||
logger.error(f"Unknown event type {event_type}") | ||
raise PrestoBaseException(f"Unknown event type {event_type}", 422) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just be passing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think passing is equivalent to what we have right now for most of these models (with the exception of classycat), not counting the validations that happen inside schema.py
I do agree that we should start implementing them, and I have created a ticket for that work (CV2-5093), but the current design is backward compatible and there is no need to implement these right now? unless you think it's urgent we address it?