diff --git a/core/admin/mailu/internal/views/dovecot.py b/core/admin/mailu/internal/views/dovecot.py index 2f5f68a4..0d56950b 100644 --- a/core/admin/mailu/internal/views/dovecot.py +++ b/core/admin/mailu/internal/views/dovecot.py @@ -33,6 +33,7 @@ def dovecot_quota(ns, user_email): user = models.User.query.get(user_email) or flask.abort(404) if ns == "storage": user.quota_bytes_used = flask.request.get_json() + user.dont_change_updated_at() models.db.session.commit() return flask.jsonify(None) diff --git a/core/admin/mailu/internal/views/fetch.py b/core/admin/mailu/internal/views/fetch.py index ccd3a159..1945b9c7 100644 --- a/core/admin/mailu/internal/views/fetch.py +++ b/core/admin/mailu/internal/views/fetch.py @@ -27,6 +27,7 @@ def fetch_done(fetch_id): fetch = models.Fetch.query.get(fetch_id) or flask.abort(404) fetch.last_check = datetime.datetime.now() fetch.error_message = str(flask.request.get_json()) + fetch.dont_change_updated_at() models.db.session.add(fetch) models.db.session.commit() return "" diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py index 70a9528f..0071bc77 100644 --- a/core/admin/mailu/models.py +++ b/core/admin/mailu/models.py @@ -25,6 +25,7 @@ from flask import current_app as app from sqlalchemy.ext import declarative from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.inspection import inspect +from sqlalchemy.orm.attributes import flag_modified from werkzeug.utils import cached_property from mailu import dkim, utils @@ -154,6 +155,10 @@ class Base(db.Model): self.__hashed = id(self) if primary is None else hash(primary) return self.__hashed + def dont_change_updated_at(self): + """ Mark updated_at as modified, but keep the old date when updating the model""" + flag_modified(self, 'updated_at') + # Many-to-many association table for domain managers managers = db.Table('manager', Base.metadata, diff --git a/towncrier/newsfragments/1363.bugfix b/towncrier/newsfragments/1363.bugfix new file mode 100644 index 00000000..edb198d7 --- /dev/null +++ b/towncrier/newsfragments/1363.bugfix @@ -0,0 +1 @@ +Do not update the updated_at field of the User model when quota_bytes_used is updated \ No newline at end of file