[GH-ISSUE #747] Update 1.2.1 -> 1.3.3 issue: modoboa_amavis.models.DoesNotExist: Policy matching query does not exist #676

Closed
opened 2026-02-27 11:12:58 +03:00 by kerem · 5 comments
Owner

Originally created by @mrh666 on GitHub (Jun 20, 2015).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/747

Hi there,

During the migration from 1.2.1 to 1.3.3 I deployed a new modoboa instance, added extensions, dbs and routers section to settings.py:

MODOBOA_APPS = (
    'modoboa',
    'modoboa.core',
    'modoboa.lib',
    # Modoboa extensions here.
    'modoboa_admin',
    'modoboa_admin_relaydomains',
    'modoboa_admin_limits',
    'modoboa_postfix_autoreply',
    'modoboa_webmail',
    'modoboa_stats',
    'modoboa_sievefilters',
    'modoboa_radicale',
    'modoboa_amavis',
)
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'modoboa',
        'USER': 'USERNAME',
        'PASSWORD': 'PASSWORD',
        'HOST': 'localhost',
        'PORT': '3306',
        'ATOMIC_REQUESTS': True,
        'OPTIONS' : {
            "init_command" : 'SET foreign_key_checks = 0;',
        },
    },
    'amavis': {
       'ENGINE': 'django.db.backends.mysql',
       'HOST': '',
       'NAME': 'amavis',
       'USER': 'USERNAME',
       'PASSWORD': 'PASSWORD',
    }
}

DATABASE_ROUTERS = ["modoboa_amavis.dbrouter.AmavisRouter"]

During migration process I run python manage.py load_initial_data and I've got the next error:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.7/site-packages/modoboa/core/management/commands/load_initial_data.py", line 55, in handle
    extension.load_initial_data()
  File "/usr/lib/python2.7/site-packages/modoboa_amavis/modo_extension.py", line 43, in load_initial_data
    policy = create_user_and_policy("@{0}".format(dom.name))
  File "/usr/lib/python2.7/site-packages/modoboa_amavis/lib.py", line 242, in create_user_and_policy
    return Policy.objects.get(policy_name=name[:32])
  File "/usr/lib64/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/django/db/models/query.py", line 357, in get
    self.model._meta.object_name)
modoboa_amavis.models.DoesNotExist: Policy matching query does not exist.

How can I fix it?

Thank you!

Originally created by @mrh666 on GitHub (Jun 20, 2015). Original GitHub issue: https://github.com/modoboa/modoboa/issues/747 Hi there, During the migration from 1.2.1 to 1.3.3 I deployed a new modoboa instance, added extensions, dbs and routers section to settings.py: ``` MODOBOA_APPS = ( 'modoboa', 'modoboa.core', 'modoboa.lib', # Modoboa extensions here. 'modoboa_admin', 'modoboa_admin_relaydomains', 'modoboa_admin_limits', 'modoboa_postfix_autoreply', 'modoboa_webmail', 'modoboa_stats', 'modoboa_sievefilters', 'modoboa_radicale', 'modoboa_amavis', ) ``` ``` DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'modoboa', 'USER': 'USERNAME', 'PASSWORD': 'PASSWORD', 'HOST': 'localhost', 'PORT': '3306', 'ATOMIC_REQUESTS': True, 'OPTIONS' : { "init_command" : 'SET foreign_key_checks = 0;', }, }, 'amavis': { 'ENGINE': 'django.db.backends.mysql', 'HOST': '', 'NAME': 'amavis', 'USER': 'USERNAME', 'PASSWORD': 'PASSWORD', } } DATABASE_ROUTERS = ["modoboa_amavis.dbrouter.AmavisRouter"] ``` During migration process I run `python manage.py load_initial_data` and I've got the next error: ``` Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line utility.execute() File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 338, in execute output = self.handle(*args, **options) File "/usr/lib/python2.7/site-packages/modoboa/core/management/commands/load_initial_data.py", line 55, in handle extension.load_initial_data() File "/usr/lib/python2.7/site-packages/modoboa_amavis/modo_extension.py", line 43, in load_initial_data policy = create_user_and_policy("@{0}".format(dom.name)) File "/usr/lib/python2.7/site-packages/modoboa_amavis/lib.py", line 242, in create_user_and_policy return Policy.objects.get(policy_name=name[:32]) File "/usr/lib64/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/usr/lib64/python2.7/site-packages/django/db/models/query.py", line 357, in get self.model._meta.object_name) modoboa_amavis.models.DoesNotExist: Policy matching query does not exist. ``` How can I fix it? Thank you!
kerem closed this issue 2026-02-27 11:12:58 +03:00
Author
Owner

@tonioo commented on GitHub (Jun 20, 2015):

Looks like you amavis database is missing some records. For each domain, you should have one record into the "policy" table and 1 record into the "users" one. In your case, the policy table is not complete. In you are in a hurry, I suggest you manually create missing records.

<!-- gh-comment-id:113766544 --> @tonioo commented on GitHub (Jun 20, 2015): Looks like you amavis database is missing some records. For each domain, you should have one record into the "policy" table and 1 record into the "users" one. In your case, the policy table is not complete. In you are in a hurry, I suggest you manually create missing records.
Author
Owner

@mrh666 commented on GitHub (Jun 20, 2015):

O! That is interesting. I found the difference in policy and users, there is one alias record, like domain.com <- domainwithsuffix.com:
in users table

id     priority     policy_id     email     fullname
11    7              11               ....          domain.com
12    7              11               ....          domainwithsuffix.com
in policy table
id      policy_name    .....
11     domain.com     .....

But if I'll create it manually, I should define it with the same id (11) which is wrong I assume.

What is proper way to do it?

P.S. During migration I break functionality of my mail system of course, but I temporary fixed it with manually inserted relay_domains instead of mysql:/etc/postfix/modoboa/sql-relaydomains.cf, commented mysql:/etc/postfix/modoboa/sql-relaydomain-aliases-transport.cf and mysql:/etc/postfix/modoboa/sql-autoreplies-transport.cf, and also used static access.db instead of mysql requests. Everything is working at the moment, just web ui is broken. So I'm not in hurry, I want to properly fix whole system.

<!-- gh-comment-id:113769722 --> @mrh666 commented on GitHub (Jun 20, 2015): O! That is interesting. I found the difference in policy and users, there is one alias record, like domain.com <- domainwithsuffix.com: in users table ``` id priority policy_id email fullname 11 7 11 .... domain.com 12 7 11 .... domainwithsuffix.com ``` ``` in policy table id policy_name ..... 11 domain.com ..... ``` But if I'll create it manually, I should define it with the same id (11) which is wrong I assume. What is proper way to do it? P.S. During migration I break functionality of my mail system of course, but I temporary fixed it with manually inserted relay_domains instead of mysql:/etc/postfix/modoboa/sql-relaydomains.cf, commented mysql:/etc/postfix/modoboa/sql-relaydomain-aliases-transport.cf and mysql:/etc/postfix/modoboa/sql-autoreplies-transport.cf, and also used static access.db instead of mysql requests. Everything is working at the moment, just web ui is broken. So I'm not in hurry, I want to properly fix whole system.
Author
Owner

@tonioo commented on GitHub (Jun 21, 2015):

You don't need to use the same id. Just create a policy with a policy_name == domainwithsuffix.com.

You need to run the postfix_maps command to update the sql map files. Check out the documentations to update your postfix configuration too :

<!-- gh-comment-id:113883684 --> @tonioo commented on GitHub (Jun 21, 2015): You don't need to use the same id. Just create a policy with a policy_name == domainwithsuffix.com. You need to run the postfix_maps command to update the sql map files. Check out the documentations to update your postfix configuration too : - http://modoboa-admin-relaydomains.readthedocs.org/en/latest/setup.html - http://modoboa.readthedocs.org/en/latest/integration/imap_and_smtp.html#postfix
Author
Owner

@tonioo commented on GitHub (Jun 29, 2015):

Does it work now ?

<!-- gh-comment-id:116523274 --> @tonioo commented on GitHub (Jun 29, 2015): Does it work now ?
Author
Owner

@tonioo commented on GitHub (Jul 18, 2015):

This issue was moved to modoboa/modoboa-amavis#19

<!-- gh-comment-id:122543524 --> @tonioo commented on GitHub (Jul 18, 2015): This issue was moved to modoboa/modoboa-amavis#19
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-modoboa#676
No description provided.