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

Backported #1616: Fix writing methods on read when reindexing services #1617

Merged
merged 3 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

1.3.5 (unreleased)
------------------

**Fixed**

- #1617 Fix writing methods on read when reindexing services


1.3.4 (2020-08-11)
------------------

Expand Down
3 changes: 2 additions & 1 deletion bika/lims/content/analysisservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ def getAvailableMethodUIDs(self):
Returns the UIDs of the available methods. it is used as a
vocabulary to fill the selection list of 'Methods' field.
"""
method_uids = self.getRawMethods()
# N.B. we return a copy of the list to avoid accidental writes
method_uids = self.getRawMethods()[:]
if self.getInstrumentEntryOfResults():
for instrument in self.getInstruments():
method_uids.extend(instrument.getRawMethods())
Expand Down
7 changes: 7 additions & 0 deletions bika/lims/upgrade/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,11 @@
handler="bika.lims.upgrade.v01_03_004.upgrade"
profile="bika.lims:default"/>

<genericsetup:upgradeStep
title="Upgrade to SENAITE.CORE 1.3.5"
source="1.3.4"
destination="1.3.5"
handler="bika.lims.upgrade.v01_03_005.upgrade"
profile="bika.lims:default"/>

</configure>
81 changes: 81 additions & 0 deletions bika/lims/upgrade/v01_03_005.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
#
# This file is part of SENAITE.CORE.
#
# SENAITE.CORE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright 2018-2020 by it's authors.
# Some rights reserved, see README and LICENSE.

from bika.lims import api
from bika.lims import logger
from bika.lims.catalog import CATALOG_ANALYSIS_REQUEST_LISTING
from bika.lims.catalog import SETUP_CATALOG
from bika.lims.config import PROJECTNAME as product
from bika.lims.upgrade import upgradestep
from bika.lims.upgrade.utils import UpgradeUtils

version = "1.3.5" # Remember version number in metadata.xml and setup.py
profile = "profile-{0}:default".format(product)

INDEXES_TO_ADD = [
# List of tuples (catalog_name, index_name, index meta type)
(CATALOG_ANALYSIS_REQUEST_LISTING, "modified", "DateIndex"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this index addition does not belong to this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just removed that code snippet 👍

]


@upgradestep(product, version)
def upgrade(tool):
portal = tool.aq_inner.aq_parent
setup = portal.portal_setup
ut = UpgradeUtils(portal)
ver_from = ut.getInstalledVersion(product)

if ut.isOlderVersion(product, version):
logger.info("Skipping upgrade of {0}: {1} > {2}".format(
product, ver_from, version))
return True

logger.info("Upgrading {0}: {1} -> {2}".format(product, ver_from, version))

# -------- ADD YOUR STUFF BELOW --------

# Fix writing methods on read when reindexing services
# https://github.com/senaite/senaite.core/pull/1617
remove_duplicate_methods_in_services(portal)

logger.info("{0} upgraded to version {1}".format(product, version))
return True


def remove_duplicate_methods_in_services(portal):
"""A bug caused duplicate methods stored in services which need to be fixed
"""
logger.info("Remove duplicate methods from services...")

cat = api.get_tool(SETUP_CATALOG)
services = cat({"portal_type": "AnalysisService"})
total = len(services)

for num, service in enumerate(services):
if num and num % 10 == 0:
logger.info("Processed {}/{} Services".format(num, total))
obj = api.get_object(service)
methods = list(set(obj.getRawMethods()))
if not methods:
continue
obj.setMethods(methods)
obj.reindexObject()

logger.info("Remove duplicate methods from services [DONE]")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from setuptools import setup, find_packages

version = '1.3.4'
version = '1.3.5'

setup(
name='senaite.core',
Expand Down