Skip to content

Commit

Permalink
CV2-5050 fix for null reference error on language resolution (#469)
Browse files Browse the repository at this point in the history
* CV2-5050 fix for null reference error on language resolution

* add test coverage for null events

* fix typo

* flesh out error expectation
  • Loading branch information
DGaffney authored Nov 4, 2024
1 parent 7818a10 commit acebba9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/main/lib/langid.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def langid(text):
prediction = cld3.get_language(text)
return {
'result': {
'language': prediction.language,
'confidence': prediction.probability
'language': prediction and prediction.language,
'confidence': prediction and prediction.probability
},
'raw': prediction,
'model': 'CLD3',
Expand Down
13 changes: 13 additions & 0 deletions app/test/test_langid.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ def test_langid_api_get_without_text(self):
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)

def test_null_prediction_cld(self):
with patch('cld3.get_language', ) as mock_cld3_get_language:
mock_cld3_get_language.return_value = None
expected = {
'result': {
'language': None,
'confidence': None
},
'raw': None,
'model': 'CLD3',
}
self.assertEqual(Cld3LangidProvider.langid("foo bar"), {'model': 'CLD3', 'raw': None, 'result': {'confidence': None, 'language': None}})

def test_langid_api_post(self):
response = self.client.post(
'/text/langid/',
Expand Down

0 comments on commit acebba9

Please sign in to comment.