Skip to content

Commit

Permalink
fix(server): correct check for empty attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Dec 13, 2022
1 parent a66d4ed commit 36f5a08
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions nlp_service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ def DocBin(
nlp = _load_spacy(req.config)
pipes_selection = {"disable": []} # if empty, spacy will raise an exception

if not req.attributes:
if req.HasField("attributes") and not req.attributes.values:
pipes_selection = {"enable": custom_components}
elif req.WhichOneof("pipes") == nlp_pb2:
elif req.WhichOneof("pipes") == "enabled_pipes":
pipes_selection = {"enable": list(req.enabled_pipes.values)}
elif req.WhichOneof("pipes") == "disabled_pipes":
pipes_selection = {"disable": list(req.disabled_pipes.values)}
Expand All @@ -263,12 +263,12 @@ def DocBin(
for sent in doc.sents:
sent._.set("vector", sent.vector)

if not req.attributes:
res.docbin = DocBin(docs=docs, store_user_data=True).to_bytes()
else:
if req.HasField("attributes"):
res.docbin = DocBin(
req.attributes.values, docs=docs, store_user_data=True
).to_bytes()
else:
res.docbin = DocBin(docs=docs, store_user_data=True).to_bytes()

return res

Expand Down

0 comments on commit 36f5a08

Please sign in to comment.