Skip to content

Update notification still fails after #10435 due to NotificationEntry uid NULL #12399

Closed

Description

@Leopoldius

Please verify that this bug has NOT been raised before.

  • I checked and didn't find a similar issue

Describe the bug*

This appears to be a follow-up to #10435.

Issue #10435 fixed the NULL target_object_id failure by using the UI notification plugin configuration as the notification target. However, the same update notification still fails later when trigger_notification() attempts to create a NotificationEntry with uid=None.

This also causes the notification to link to the UI notification plugin configuration and display "Plugin Detail - undefined" when clicked.

The scheduled InvenTree.tasks.check_for_updates task creates an update_available UI notification with no target object:

trigger_notification(
    None,
    'update_available',
    ...
)

The UI notification is successfully created, but the task then fails when recording the notification entry:

django.db.utils.IntegrityError:
null value in column "uid" of relation "common_notificationentry"
violates not-null constraint

The failure occurs because obj_ref_value is None and is passed to:

NotificationEntry.notify(category, obj_ref_value)

while the model declares:

uid = models.IntegerField()

As a result, the scheduled task fails every day and creates another duplicate UI notification.

Additionally, InvenTreeUINotifications.send_notification() replaces the missing target with its own plugin configuration:

if not target:
    target = self.plugin_config()

Therefore clicking the update notification attempts to open a plugin detail page and displays:

Plugin Detail - undefined
Plugin Inactive
Plugin is not active
Image Image

Relevant traceback

File "InvenTree/tasks.py", line 671, in check_for_updates
    trigger_notification(None, 'update_available', ...)

File "common/notifications.py", line 218, in trigger_notification
    NotificationEntry.notify(category, obj_ref_value)

File "common/models.py", in notify
    get_or_create(key=key, uid=uid)

django.db.utils.IntegrityError:
null value in column "uid" of relation "common_notificationentry"
violates not-null constraint

Additional investigation

The GitHub API already returns a valid release URL in the response from:

https://api.github.com/repos/inventree/inventree/releases/latest

For the current release, the relevant fields are:

tag_name: 1.4.1
html_url: https://github.com/inventree/InvenTree/releases/tag/1.4.1

However, check_for_updates() only reads tag_name:

tag = data.get('tag_name', None)

The html_url field is ignored and is not passed to the notification system.

The UI notification plugin also does not use a link from the notification context. It only stores:

name=ctx.get('name')
message=ctx.get('message')

The resulting notification API response currently contains:

target.model_type = pluginconfig
target.model_id = 10
target.link = https://parts.embedded.homes/admin/plugin/pluginconfig/10/change/

This confirms that the incorrect link is generated by the backend serializer from the fallback PluginConfig target, rather than by the frontend.

The effective flow is:

trigger_notification(None, 'update_available')
    -> target = self.plugin_config()
    -> NotificationMessage.target_object = PluginConfig
    -> NotificationMessageSerializer uses the staff admin URL fallback
    -> clicking the notification opens the plugin configuration page

A search of production call sites also shows that update_available is the only current call to trigger_notification() which passes obj=None. Other notification calls provide a real model instance.

Another detail is that record_task_success('check_for_updates') is called before notification delivery. Therefore the update check is recorded as successful, but the background task subsequently raises an IntegrityError while recording the NotificationEntry.

Suggested direction

A global notification needs an explicit stable deduplication identifier instead of None. The notification also needs an explicit destination URL or dedicated handling for the update_available category instead of using the UI notification plugin configuration as its target.

Steps to Reproduce

  1. Run an InvenTree version older than the current stable release.
  2. Enable the scheduled update check.
  3. Wait for or manually invoke InvenTree.tasks.check_for_updates.
  4. Check the worker log.
  5. Open the generated Update Available notification in the UI.

Actual behaviour

  • The UI notification is created.
  • Insertion into common_notificationentry fails because uid is NULL.
  • The update check is recorded as successful before notification delivery, but the background task subsequently raises an IntegrityError while recording NotificationEntry.
  • A new duplicate notification is created on every scheduled run.
  • Clicking the notification opens Plugin Detail - undefined.

Expected behaviour

  • The update notification should be successfully deduplicated.
  • The scheduled task should complete without an exception.
  • Clicking the notification should open the relevant release or update page, or the notification should be intentionally non-clickable.

Deployment Method

Docker

Version Information

Version information

InvenTree: 1.4.1
API: 511
Python: 3.14.6
Django: 5.2.15
Deployment: official Docker image
Database: PostgreSQL 17

Relevant database schema

common_notificationentry.uid integer NOT NULL

Try to reproduce on the demo site

I did not try to reproduce

Is the bug reproducible on the demo site?

Not reproducible

Relevant log output

Activity

  1. added
    bug
    question
    triage:not-checked
    on Jul 14, 2026
  2. Leopoldius commented on Jul 14, 2026

    @Leopoldius
    ContributorAuthor

    I investigated the existing test coverage for this task, and it appears that the current test_task_check_for_updates() does not exercise the failing notification path.

    The test currently verifies only that _INVENTREE_LATEST_VERSION becomes non-empty after running check_for_updates():

    InvenTree.tasks.offload_task(InvenTree.tasks.check_for_updates)
    
    response = InvenTreeSetting.get_setting(
        '_INVENTREE_LATEST_VERSION'
    )
    self.assertNotEqual(response, '')
    

    It does not:

    • create an active superuser recipient;
    • force the installed version to be older than the mocked latest release;
    • verify that NotificationMessage is created;
    • verify that NotificationEntry is created;
    • verify that the deduplication UID is valid;
    • run the task twice to verify that duplicate notifications are suppressed;
    • inspect the generated notification target or link.

    As a result, the test can pass even if the update_available notification branch is never entered, or if notification delivery subsequently raises an IntegrityError.

    A regression test for this issue should invoke the global notification path with obj=None and assert that:

    1. The first call creates exactly one NotificationMessage.
    2. A valid NotificationEntry is recorded without a NULL UID.
    3. A second call within the deduplication period does not create another message.
    4. The generated notification does not point to the UI notification plugin configuration.
    5. The notification link resolves to the corresponding release page, or is intentionally absent.

    The existing core notification tests also only call trigger_notification() with a real model instance, such as a user object. Therefore they do not cover the global notification case which triggered both #10435 and this issue.

  3. SchrodingersGat commented on Jul 15, 2026

    @SchrodingersGat
    Member

    @Leopoldius it sounds like you have enough information to submit a fix and regression test for this issue? :)

  4. Leopoldius commented on Jul 16, 2026

    @Leopoldius
    ContributorAuthor

    @Leopoldius it sounds like you have enough information to submit a fix and regression test for this issue? :)

    I can prepare a fix and regression test.

    Before I do, could you confirm the preferred approach for notifications without a model object?

    My current proposal is:

    • allow trigger_notification() to receive an explicit deduplication UID for global notifications;
    • use a stable UID for update_available instead of making NotificationEntry.uid nullable;
    • preserve the GitHub release html_url as the explicit notification link, rather than falling back to the PluginConfig admin URL.

    If that direction is acceptable, I can put together a focused PR.

    BR,
    Leo

  5. br413 commented on Jul 17, 2026

    @br413
    Contributor

    I'd like to pick this up if @Leopoldius is not already preparing a PR. I plan to implement the approach you outlined: explicit deduplication UID for global notifications, stable UID for update_available, and pass the GitHub release html_url as the notification link instead of falling back to PluginConfig. I'll include the regression tests you described. Could this be assigned to me?

  6. Leopoldius commented on Jul 17, 2026

    @Leopoldius
    ContributorAuthor

    Hi @br413, thanks for offering to help. I already started working on the fix and regression tests yesterday evening, and I was planning to finish and submit the PR over the weekend.

    To avoid duplicating the work, I 'd like to continue with the implementation and link the PR here once it is ready. Feedback and review would be very welcome.

  7. br413 commented on Jul 17, 2026

    @br413
    Contributor

    Sounds great,
    thank you for the update. I’m looking forward to seeing the PR and hope everything goes smoothly.

  8. Leopoldius commented on Jul 17, 2026

    @Leopoldius
    ContributorAuthor

    Thanks, that's nice of you.

  9. removed
    triage:not-checked
    on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugquestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions