# Unable to save model from trainer

**URL:** <https://discourse.cogstack.org/t/unable-to-save-model-from-trainer/378>\
**Category:** MedCAT\
**Created:** [April 2, 2026, 3:44pm UTC](https://discourse.cogstack.org/t/unable-to-save-model-from-trainer/378 "2026-04-02T15:44:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TKaplan](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@TKaplan](https://discourse.cogstack.org/u/TKaplan)\
**Post date:** [April 2, 2026, 3:44pm UTC](https://discourse.cogstack.org/t/unable-to-save-model-from-trainer/378/1 "2026-04-02T15:44:09Z")

</div>

I’m getting the below error (`AttributeError: 'NoneType' object has no attribute 'cdb_file'`) when attemping to save a model from “Save Model” button on the MedCAT trainer landing page, following a bunch of submitted annotations (with “train on submit” enabled via admin).

This was incremental training of the v2\_Snomed2025 publicly available MedCATv2 model. I can see a cdb in the admin page (`/home/api/media/v2_Snomed2025_MIMIC_IV_bbe806e192df009f_9Xv5lF5/cdb`), so I wouldn’t expect this to be an issue?

Any suggestions for debugging would be welcome, thank you!

medcat v2.6.0, trainer image built from source.

```auto
nginx-1 | 172.18.0.1 - - [02/Apr/2026:15:24:05 +0000] "POST /api/save-models/ HTTP/1.1" 500 91672 "http://localhost:8001/" ""

medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/rest_framework/views.py", line 486, in raise_uncaught_exception
medcattrainer-1 | [medcattrainer] raise exc
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/rest_framework/views.py", line 512, in dispatch
medcattrainer-1 | [medcattrainer] response = handler(request, *args, **kwargs)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/rest_framework/decorators.py", line 50, in handler
medcattrainer-1 | [medcattrainer] return func(*args, **kwargs)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] File "/home/api/api/views.py", line 566, in save_models
medcattrainer-1 | [medcattrainer] cat.cdb.save(project.concept_db.cdb_file.path)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] AttributeError: 'NoneType' object has no attribute 'cdb_file'
medcattrainer-1 | [medcattrainer] ERROR 2026-04-02 15:24:05,131 log.py l:253:Internal Server Error: /api/save-models/
medcattrainer-1 | [medcattrainer] Traceback (most recent call last):
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
medcattrainer-1 | [medcattrainer] response = get_response(request)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
medcattrainer-1 | [medcattrainer] response = wrapped_callback(request, *callback_args, **callback_kwargs)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
medcattrainer-1 | [medcattrainer] return view_func(request, *args, **kwargs)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 105, in view
medcattrainer-1 | [medcattrainer] return self.dispatch(request, *args, **kwargs)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/rest_framework/views.py", line 515, in dispatch
medcattrainer-1 | [medcattrainer] response = self.handle_exception(exc)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/rest_framework/views.py", line 475, in handle_exception
medcattrainer-1 | [medcattrainer] self.raise_uncaught_exception(exc)
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/rest_framework/views.py", line 486, in raise_uncaught_exception
medcattrainer-1 | [medcattrainer] raise exc
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/rest_framework/views.py", line 512, in dispatch
medcattrainer-1 | [medcattrainer] response = handler(request, *args, **kwargs)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] File "/home/.venv/lib/python3.12/site-packages/rest_framework/decorators.py", line 50, in handler
medcattrainer-1 | [medcattrainer] return func(*args, **kwargs)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] File "/home/api/api/views.py", line 566, in save_models
medcattrainer-1 | [medcattrainer] cat.cdb.save(project.concept_db.cdb_file.path)
medcattrainer-1 | [medcattrainer] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
medcattrainer-1 | [medcattrainer] AttributeError: 'NoneType' object has no attribute 'cdb_file'

```

---

<div class="post-metadata">

**Author:** ![mart.ratas](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mart.ratas](https://discourse.cogstack.org/u/mart.ratas)\
**Post date:** [April 7, 2026, 12:15pm UTC](https://discourse.cogstack.org/t/unable-to-save-model-from-trainer/378/2 "2026-04-07T12:15:10Z")

</div>

Hi!

Sorry for the delayed response. Long holidays and all that.

I’ve managed to replicate the issue on our side as well. So the good news is that it’s not an issue on your side specifically.

Before going on to describing why this happens, I’ll suggest a workaround (at least for now):  
Instead of having the trainer do the training, use the admin panel to download the trainer export (under Project annotate entities) and do the fine-tuning outside of trainer.

As for the issue at hand. I’m pretty sure this is an issue with old CDB/Vocab based model usage (which is largely deprecated now). Because just a single model pack is used instead, the `concept_db` is empty (`None`) for projects created with a model pack instead. However - clearly - the change to use model packs insteads hasn’t fully been implemented here.

PS: If you did in fact use separate CDB / Vocab for this model instead of a model pack, do let me know (I doubt it). That would make this a more difficult issue to debug.

We’ll try to fix this in the near future. Thanks for bringing this to our attention!

---

<div class="post-metadata">

**Author:** ![TKaplan](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@TKaplan](https://discourse.cogstack.org/u/TKaplan)\
**Post date:** [April 7, 2026, 2:17pm UTC](https://discourse.cogstack.org/t/unable-to-save-model-from-trainer/378/3 "2026-04-07T14:17:19Z")

</div>

Thanks for such a quick response, I’ve exported (thanks for pointing me towards the admin action) and now the model is happily tagging new concepts - was wondering why this wasn’t starting to work in the GUI training loop.

---

<div class="post-metadata">

**Author:** ![mart.ratas](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mart.ratas](https://discourse.cogstack.org/u/mart.ratas)\
**Post date:** [April 7, 2026, 2:49pm UTC](https://discourse.cogstack.org/t/unable-to-save-model-from-trainer/378/4 "2026-04-07T14:49:24Z")

</div>

I’m glad my proposed workaround worked for you.

Though - somewhat obviously - it’s not a good workaround, especially for situations where you might need to do this multiple times manually.

There is a PR up already that _should_ fix the underlying issue:

> <https://github.com/CogStack/cogstack-nlp/pull/402>
>
> Hopefully this fixes:
> 
> https://discourse.cogstack.org/t/unable-to-save-model-f…rom-trainer/378
> 
> The idea is to allow model pack based projects to overwrite their model packs as the CDB based ones were designed to.
> Though notably without the \`overwrite=True\` option they, too, would probably have failed.
> 
> So this PR does the following:
> \- Creates a separate function to do the model pack overwriting if/when required
> \- Moves the old model pack to a temporary folder
> - Because the \`CAT.save\_model\_pack\` method doesn't allow (or delegate the allowing of) overwriting existing ifles
> - And if we just removed the previous file(s) I'd be afraid of leaving a state with a model pack path that refers to nothing
> - If all goes well, the copy is destroyed after
> - If something fails, attempt to move the old one back to its original location

But I can’t promise a release window with the fix, I’m afrair. Though if you’re building from source, you’re welcome to do so based on that branch. But with the caveat that this PR hasn’t been merged in (i.e hasn’t been reviewed by others on the team).
