Skip to content

fix(medcat-trainer): Fix Try Model bug after medcat V2#531

Merged
alhendrickson merged 2 commits into
mainfrom
fix/medcat-trainer/try-model
Jun 11, 2026
Merged

fix(medcat-trainer): Fix Try Model bug after medcat V2#531
alhendrickson merged 2 commits into
mainfrom
fix/medcat-trainer/try-model

Conversation

@alhendrickson

@alhendrickson alhendrickson commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Fixes two issues with the try model page

image

500 Error on /api/annotate-text/

Error introduced in this PR

https://github.com/CogStack/cogstack-nlp/pull/309/changes

[medcattrainer] AttributeError: 'set' object has no attribute 'check_filters'
[medcattrainer] ERROR 2026-06-10 15:34:57,522 log.py l:253:Internal Server Error: /api/annotate-text/
[medcattrainer] Traceback (most recent call last):
[medcattrainer] File "/home/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
[medcattrainer] response = get_response(request)

...
 
[medcattrai
[medcattrainer] response = handler(request, *args, **kwargs)
[medcattrainer] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[medcattrainer] File "/home/.venv/lib/python3.12/site-packages/rest_framework/decorators.py", line 50, in handler
[medcattrainer] return func(*args, **kwargs)
[medcattrainer] ^^^^^^^^^^^^^^^^^^^^
[medcattrainer] File "/home/api/api/views.py", line 781, in annotate_text
[medcattrainer] spacy_doc = cat(message)
[medcattrainer] ^^^^^^^^^^^^
[medcattrainer] File "/home/.venv/lib/python3.12/site-packages/medcat/cat.py", line 114, in __call__
[medcattrainer] doc = self._pipeline.get_doc(text)
[medcattrainer] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[medcattrainer] File "/home/.venv/lib/python3.12/site-packages/medcat/pipeline/pipeline.py", line 331, in get_doc

No entities returned

Original code then seems to be dependent on each Entity being loaded in already, but it really doesnt have to.

I'm not sure when the Entity table is meant to get loaded, so this is technically a work around, but really it's just simplifying it.

Current flow:

  • Get entities from medcat
  • Check they are loaded into the Entity database, and return Entity IDs to the UI.
  • Filter anything not in the database
  • Then in the UI, resolve Entity ID to CUI

New flow

  • Get entities from medcat
  • As seemingly an unused step - Check they are loaded into the Entity database, and get the Entity ID. Dont filter
  • Return CUIs to the UI
  • Then in the UI, dont resolve the CUI again

@tomolopolis tomolopolis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - nice thanks for picking up this fix

@alhendrickson alhendrickson merged commit 646f7c1 into main Jun 11, 2026
11 of 13 checks passed
@alhendrickson alhendrickson deleted the fix/medcat-trainer/try-model branch June 11, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants