Manual meta-task selection overwritten when using model pack without MetaCAT models

### Summary

In MedCAT Trainer 3.6.1, manually selected meta-annotation tasks are automatically cleared when a project uses a model pack that does not contain MetaCAT models. This prevents users from setting up manual meta-annotation tasks for training MetaCAT models from scratch.

### Environment

- **MedCAT Trainer version:** 3.6.1 (broken), 3.6.0 (working)

- **Deployment:** Docker container

- **Model pack:** Base NER+L model without MetaCAT models

### Steps to Reproduce

1. Spin up a new instance of MedCAT Trainer 3.6.1

2. Upload a model pack that does **not** contain MetaCAT models (e.g. a base NER+L model pack)

3. Upload a dataset and import the CDB to Solr

4. Create a MetaTask (e.g. “Presence”) with MetaTaskValues (e.g. current, hypothetical, negated)

5. In Django admin, edit a `ProjectAnnotateEntities` project and select the “Presence” meta-task in the tasks field

6. Save the project

7. Check the project’s meta_tasks via mctclient or Django admin

### Expected Behaviour

Manually selected meta-tasks persist on the project, allowing users to configure manual meta-annotation workflows when training MetaCAT models from scratch.

### Actual Behaviour

The manually selected meta-tasks are immediately cleared and replaced with an empty list.

So I pushed this through claude and it suggested the following problem:

The signal handler `project_tasks_changed` overwrites the selection with tasks derived from the model pack’s MetaCAT models — which is empty when the model pack has none.

and fix:

```python

def project_tasks_changed(sender, instance, action, **kwargs):

if (action.startswith(‘post’) and isinstance(instance, ProjectAnnotateEntitiesFields) and

        instance.model_pack is not None and instance.model_pack.meta_cats.exists()):

    instance.tasks.set(\[MetaTask.objects.filter(prediction_model_id=meta_cat.id).first()

for meta_cat in instance.model_pack.meta_cats.all()])

```

but unfortunately this doesn’t seem to actually fix the problem. I am not good enough at python to be able to solve the root cause of this problem unfortunately.

Very happy to help try to give more information to solve this problem, or be pointed in correct direction if I am doing something wrong; fix for me at present it to move back 3.6.0 which does work with meta annotation.

Thank you for the feedback along with the suggested fix.

My initial look would suggest that claude was right and that should be the fix. But we will investigate.

When you say that didn’t work for you, do you mean that it didn’t fix it for existing projects or that it didn’t fix it for new ones either? Did you verify that you were running your patched version of the software?

Thanks again for your query and input!

As far as we can tell this should be fixed in the next release of medcat trainer (2.6.2 or 2.7.0). We should be able to push that out in the coming days.

Thanks for such a prompt reply & great project. I’ll give it a spin once it’s available.

Can confirm that 3.7.0 seems to be working correctly. Thanks for fixing.

1 Like