-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Conversation
bika/lims/content/attachment.py
Outdated
if analysis_request: | ||
return getCurrentState(analysis_request) | ||
|
||
return '' |
There was a problem hiding this comment.
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)))
?
There was a problem hiding this comment.
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
bika/lims/content/attachment.py
Outdated
return None | ||
|
||
if len(analysis) > 1: | ||
logger.warn("Single attachment assigned to more than one Analysis") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
bika/lims/content/attachment.py
Outdated
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bika/lims/content/attachment.py
Outdated
|
||
return '%s - %s' % (request_id, analysis.Title()) | ||
|
||
|
There was a problem hiding this comment.
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...
bika/lims/content/attachment.py
Outdated
return requestid | ||
else: | ||
request_id = self.getRequestID() | ||
if not request_id: | ||
return None |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
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 anUIDReferenceField
. The code frombika.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 usingget_backreferences
function frombika.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:
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.