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

Update 1.2.1 -> 1.3.3 issue: modoboa_amavis.models.DoesNotExist: Policy matching query does not exist #747

Closed
mrh666 opened this issue Jun 20, 2015 · 5 comments

Comments

@mrh666
Copy link

mrh666 commented Jun 20, 2015

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!

@tonioo
Copy link
Member

tonioo commented 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.

@mrh666
Copy link
Author

mrh666 commented 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.

@tonioo
Copy link
Member

tonioo commented 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 :

@tonioo
Copy link
Member

tonioo commented Jun 29, 2015

Does it work now ?

@tonioo
Copy link
Member

tonioo commented Jul 18, 2015

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

@tonioo tonioo closed this as completed Jul 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants