Skip to content
This repository has been archived by the owner on Feb 28, 2021. It is now read-only.

Bug in saving profane word in redis #28

Closed
weirdname404 opened this issue Apr 21, 2020 · 1 comment · Fixed by #29 or weirdname404/profanity-filter#1
Closed

Bug in saving profane word in redis #28

weirdname404 opened this issue Apr 21, 2020 · 1 comment · Fixed by #29 or weirdname404/profanity-filter#1

Comments

@weirdname404
Copy link
Contributor

Expected behavior
Profane word is saved in redis.

Real behavior
Exception is thrown.

How to reproduce

  1. Connect to redis
  2. censor profane word
pf = ProfanityFilter(cache_redis_connection_url='redis://redis:6379/1')
pf.censor('fuck')

_save_censored_word will fail` method will throw an exception

Traceback (most recent call last):                                                                                                                                                                                 
  File "<console>", line 1, in <module>                                                                                                                                                                            
  File "/code/ratings_parser/utils/censorship/profanity_filter.py", line 15, in censor                                                                                                                             
    return pf.censor(text)                                                                                                                                                                                         
  File "/usr/local/lib/python3.8/site-packages/profanity_filter/profanity_filter.py", line 201, in censor                                                                                                          
    return self._censor(text=text, return_bool=False)                                                                                                                                                              
  File "/usr/local/lib/python3.8/site-packages/profanity_filter/profanity_filter.py", line 796, in _censor                                                                                                         
    doc = self._parse(language=language, text=text_part)                                                                                                                                                           
  File "/usr/local/lib/python3.8/site-packages/profanity_filter/profanity_filter.py", line 523, in _parse                                                                                                          
    return spacy_utlis.parse(nlp=nlp, text=text, language=language, use_profanity_filter=use_profanity_filter)                                                                                                     
  File "/usr/local/lib/python3.8/site-packages/profanity_filter/spacy_utlis.py", line 19, in parse                                                                                                                 
    return nlp(text, disable=disable, component_cfg=component_cfg)                                                                                                                                                 
  File "/usr/local/lib/python3.8/site-packages/spacy/language.py", line 439, in __call__                                                                                                                           
    doc = proc(doc, **component_cfg.get(name, {}))                                                                                                                                                                 
  File "/usr/local/lib/python3.8/site-packages/profanity_filter/spacy_component.py", line 37, in __call__                                                                                                          
    span = self._censor_spaceless_span(doc[i:j], language=language)                                                                                                                                                
  File "/usr/local/lib/python3.8/site-packages/profanity_filter/spacy_component.py", line 78, in _censor_spaceless_span                                                                                            
    censored_word = self._profanity_filter.censor_word(word=token, language=language)                                                                                                                              
  File "/usr/local/lib/python3.8/site-packages/profanity_filter/profanity_filter.py", line 206, in censor_word                                                                                                     
    return self._censor_word(language=language, word=word)                                                                                                                                                         
  File "/usr/local/lib/python3.8/site-packages/profanity_filter/profanity_filter.py", line 710, in _censor_word                                                                                                    
    censored_censored_part, no_profanity_inside = self._censor_word_part(language=language,                                                                                                                        
  File "/usr/local/lib/python3.8/site-packages/profanity_filter/profanity_filter.py", line 659, in _censor_word_part                                                                                               
    self._save_censored_word(censored_word)                                                                                                                                                                        
  File "/usr/local/lib/python3.8/site-packages/profanity_filter/profanity_filter.py", line 630, in _save_censored_word                                                                                             
    d = asdict(word)                                                                                                                                                                                               
  File "/usr/local/lib/python3.8/dataclasses.py", line 1072, in asdict                                                                                                                                             
    raise TypeError("asdict() should be called on dataclass instances")                                                                                                                                            
TypeError: asdict() should be called on dataclass instances
@rominf
Copy link
Owner

rominf commented Apr 30, 2020

I uploaded a new version to PyPI. Thanks for the report and fix!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants