diff --git a/HISTORY.rst b/HISTORY.rst index afdc9794b6..c60dcfa746 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,3 +1,8 @@ +3.2.3 (2019-06-XX) +================== +* Add support for disabling the random primary key + test mixin. + 3.2.2 (2019-06-19) ================== * Fix document type change view. Closes GitLab issue #614 diff --git a/docs/releases/3.2.3.rst b/docs/releases/3.2.3.rst new file mode 100644 index 0000000000..60dc84d965 --- /dev/null +++ b/docs/releases/3.2.3.rst @@ -0,0 +1,103 @@ +Version 3.2.3 +============= + +Released: June XX, 2019 + + +Changes +------- + +- Add support for disabling the random primary key + test mixin. + + +Removals +-------- + +- None + + +Upgrading from a previous version +--------------------------------- + +If installed via Python's PIP +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Remove deprecated requirements:: + + $ curl https://gitlab.com/mayan-edms/mayan-edms/raw/master/removals.txt | pip uninstall -r /dev/stdin + +Type in the console:: + + $ pip install mayan-edms==3.2.1 + +the requirements will also be updated automatically. + + +Using Git +^^^^^^^^^ + +If you installed Mayan EDMS by cloning the Git repository issue the commands:: + + $ git reset --hard HEAD + $ git pull + +otherwise download the compressed archived and uncompress it overriding the +existing installation. + +Remove deprecated requirements:: + + $ pip uninstall -y -r removals.txt + +Next upgrade/add the new requirements:: + + $ pip install --upgrade -r requirements.txt + + +Common steps +^^^^^^^^^^^^ + +Perform these steps after updating the code from either step above. + +Make a backup of your supervisord file:: + + sudo cp /etc/supervisor/conf.d/mayan.conf /etc/supervisor/conf.d/mayan.conf.bck + +Update the supervisord configuration file. Replace the environment +variables values show here with your respective settings. This step will refresh +the supervisord configuration file with the new queues and the latest +recommended layout:: + + MAYAN_DATABASE_ENGINE=django.db.backends.postgresql MAYAN_DATABASE_NAME=mayan \ + MAYAN_DATABASE_PASSWORD=mayanuserpass MAYAN_DATABASE_USER=mayan \ + MAYAN_DATABASE_HOST=127.0.0.1 MAYAN_MEDIA_ROOT=/opt/mayan-edms/media \ + /opt/mayan-edms/bin/mayan-edms.py platformtemplate supervisord > /etc/supervisor/conf.d/mayan.conf + +Edit the supervisord configuration file and update any setting the template +generator missed:: + + vi /etc/supervisor/conf.d/mayan.conf + +Migrate existing database schema with:: + + $ mayan-edms.py performupgrade + +Add new static media:: + + $ mayan-edms.py preparestatic --noinput + +The upgrade procedure is now complete. + + +Backward incompatible changes +----------------------------- + +- None + + +Bugs fixed or issues closed +--------------------------- + +- :gitlab-issue:`615` + +.. _PyPI: https://pypi.python.org/pypi/mayan-edms/ diff --git a/docs/releases/index.rst b/docs/releases/index.rst index 9bd92aea1f..ec60a82fa4 100644 --- a/docs/releases/index.rst +++ b/docs/releases/index.rst @@ -20,6 +20,7 @@ versions of the documentation contain the release notes for any later releases. .. toctree:: :maxdepth: 1 + 3.2.3 3.2.2 3.2.1 3.2 diff --git a/mayan/apps/common/tests/mixins.py b/mayan/apps/common/tests/mixins.py index ce1f198bcf..1060f9c4ea 100644 --- a/mayan/apps/common/tests/mixins.py +++ b/mayan/apps/common/tests/mixins.py @@ -144,6 +144,7 @@ class RandomPrimaryKeyModelMonkeyPatchMixin(object): random_primary_key_random_floor = 100 random_primary_key_random_ceiling = 10000 random_primary_key_maximum_attempts = 100 + random_primary_key_enable = True @staticmethod def get_unique_primary_key(model): @@ -170,47 +171,49 @@ class RandomPrimaryKeyModelMonkeyPatchMixin(object): return primary_key def setUp(self): - self.method_save_original = models.Model.save + if self.random_primary_key_enable: + self.method_save_original = models.Model.save - def method_save_new(instance, *args, **kwargs): - if instance.pk: - return self.method_save_original(instance, *args, **kwargs) - else: - # Set meta.auto_created to True to have the original save_base - # not send the pre_save signal which would normally send - # the instance without a primary key. Since we assign a random - # primary key any pre_save signal handler that relies on an - # empty primary key will fail. - # The meta.auto_created and manual pre_save sending emulates - # the original behavior. Since meta.auto_created also disables - # the post_save signal we must also send it ourselves. - # This hack work with Django 1.11 .save_base() but can break - # in future versions if that method is updated. - pre_save.send( - sender=instance.__class__, instance=instance, raw=False, - update_fields=None, - ) - instance._meta.auto_created = True - instance.pk = RandomPrimaryKeyModelMonkeyPatchMixin.get_unique_primary_key( - model=instance._meta.model - ) - instance.id = instance.pk + def method_save_new(instance, *args, **kwargs): + if instance.pk: + return self.method_save_original(instance, *args, **kwargs) + else: + # Set meta.auto_created to True to have the original save_base + # not send the pre_save signal which would normally send + # the instance without a primary key. Since we assign a random + # primary key any pre_save signal handler that relies on an + # empty primary key will fail. + # The meta.auto_created and manual pre_save sending emulates + # the original behavior. Since meta.auto_created also disables + # the post_save signal we must also send it ourselves. + # This hack work with Django 1.11 .save_base() but can break + # in future versions if that method is updated. + pre_save.send( + sender=instance.__class__, instance=instance, raw=False, + update_fields=None, + ) + instance._meta.auto_created = True + instance.pk = RandomPrimaryKeyModelMonkeyPatchMixin.get_unique_primary_key( + model=instance._meta.model + ) + instance.id = instance.pk - result = instance.save_base(force_insert=True) - instance._meta.auto_created = False + result = instance.save_base(force_insert=True) + instance._meta.auto_created = False - post_save.send( - sender=instance.__class__, instance=instance, created=True, - update_fields=None, raw=False - ) + post_save.send( + sender=instance.__class__, instance=instance, created=True, + update_fields=None, raw=False + ) - return result + return result - setattr(models.Model, 'save', method_save_new) + setattr(models.Model, 'save', method_save_new) super(RandomPrimaryKeyModelMonkeyPatchMixin, self).setUp() def tearDown(self): - models.Model.save = self.method_save_original + if self.random_primary_key_enable: + models.Model.save = self.method_save_original super(RandomPrimaryKeyModelMonkeyPatchMixin, self).tearDown()