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

Traceback error when deleting attachment from Analysis Request #452

Merged
merged 3 commits into from
Dec 7, 2017

Conversation

xispa
Copy link
Member

@xispa xispa commented Dec 7, 2017

Description of the issue/feature this PR addresses

The user cannot remove an attachment from an Analysis Request, but assigned to a particular Analysis. The reason is that while the relationship between AnalysisRequest and Attachment still uses ReferenceField, the relationship between Analysis and Attachment is based on an UIDReferenceField. The code from bika.lims.content.attachment that retrieves either the Analysis Request or the Analysis was always using the reference catalog. With this Pull Request, the retrieval of the Analysis the current Attachment is related to is done by using get_backreferences function from bika.lims.browser.uidreferencefield.

Linked issue: Traceback error when deleting attachment from AR #441

Current behavior before PR

A traceback is rised when trying to remove an Attachment from an Analysis Request that was explicitly assigned to an Analysis:

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module bika.lims.browser.attachment, line 81, in __call__
  Module bika.lims.browser.attachment, line 100, in action_update
  Module bika.lims.browser.attachment, line 189, in delete_attachment
AttributeError: 'NoneType' object has no attribute 'getAttachment'

Desired behavior after PR is merged

The user can remove an Attachment from an Analysis Request that was explicitly assigned to an Analysis.

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

if analysis_request:
return getCurrentState(analysis_request)

return ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about the possibilities to come to this point in code. Shall we add a logger.warn('Free floating attachment detected: {}'.format(repr(self)))?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed getParentState function. Is not used anywhere in the code and seems quite awkward to me

return None

if len(analysis) > 1:
logger.warn("Single attachment assigned to more than one Analysis")
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question for better understanding: Why is it not allowed to have a single attachment attached to more than one Analysis? Wouldn't it make sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing stops you to add more than one Attachment to the same Analysis, of course. Even the same file. What you cannot do is to associate the same Attachment object (with the same UID) to more than one Analysis. Every time you add an attachment, a new Attachment object will be created and associated to an Analysis, even if that Analysis already has other Attachment objects associated. Here we are using self(this particular instance of Attachment, with it's own UID) to get its back references, that atm, can only be one Analysis.
We could change and allow the user to associate multiple analyses to a single analysis in just one shot, of course. Then, the first thing we'd need to change is the attachments widget.


return '%s - %s' % (request_id, analysis.Title())


def getRequest(self):
"""Return the AR to which this is linked there is a short time between
creation and linking when it is not linked
Copy link
Contributor

Choose a reason for hiding this comment

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


return '%s - %s' % (request_id, analysis.Title())


Copy link
Contributor

Choose a reason for hiding this comment

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

reduce to single blank lines between methods.
Sorry, that might seem picky, but at least my flake8 linter is always complaining about these small issues...

return requestid
else:
request_id = self.getRequestID()
if not request_id:
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

Better return an empty string here, so it fit's better with the return type in line 149

# from there.
analysis = self.getAnalysis()
if IRequestAnalysis.providedBy(analysis):
return analysis.getRequest()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please be aware that you reach that point in code also if len(uids) != 1

@ramonski ramonski merged commit cf1f751 into senaite:master Dec 7, 2017
@xispa xispa deleted the i441 branch December 7, 2017 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants