Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Notification verb is saved in database #334

Open
pandafy opened this issue Feb 12, 2025 · 1 comment · May be fixed by #335
Open

[bug] Notification verb is saved in database #334

pandafy opened this issue Feb 12, 2025 · 1 comment · May be fixed by #335
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@pandafy
Copy link
Member

pandafy commented Feb 12, 2025

Describe the bug
The notification verb is saved in the database. Thus, changing the verb in the NOTIFICATION_TYPE does not change the message of existing notifications.

Steps To Reproduce
Steps to reproduce the behavior:

  1. Create a default notification using the create_notification management command.
  2. Go to Django admin and verify the notification message.
Default notification with default verb and level info by default
  1. Change the verb for the default notification type
    'default': {
    'level': 'info',
    'verb': 'default verb',
    'verbose_name': 'Default Type',
    'email_subject': '[{site.name}] Default Notification Subject',
    'message': (
    'Default notification with {notification.verb} and level {notification.level}'
    ' by [{notification.target}]({notification.target_link})'
    ),
    'message_template': 'openwisp_notifications/default_message.md',
    'email_notification': True,
    'web_notification': True,
    },
  2. Go to Django admin again and verify the notification message

Expected behavior
The notification message should show the updated notification verb

Possible solution

Update the notify handler to not save the verb in the database.

notification = Notification(
recipient=recipient,
actor=actor,
verb=str(verb),
public=public,
description=description,
timestamp=timestamp,
level=level,
type=notification_type,
)

Update the AbstractNotification model to use the verb from the configuration if database value is set to None

@pandafy pandafy added the bug Something isn't working label Feb 12, 2025
@pandafy pandafy moved this from To do (general) to To do (Python & Django) in OpenWISP Contributor's Board Feb 12, 2025
@pandafy pandafy added the good first issue Good for newcomers label Feb 12, 2025
@nemesifier nemesifier moved this from Backlog to To do in OpenWISP Priorities for next releases Feb 12, 2025
@shwetd19
Copy link

Hey @pandafy, I think the solution approach is to make the verb field nullable, by updating the handler to make verb optional, and add a get_verb() method that prioritizes NOTIFICATION_TYPES config while falling back to the database value, with checking.. notifications properly reflect updated verbs while maintaining backward compatibility can solve this bug

can I give it a try ?

@AviGawande AviGawande linked a pull request Feb 15, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: To do (Python & Django)
Development

Successfully merging a pull request may close this issue.

2 participants