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

AR Add: No sample points are found if a sample type was set #443

Closed
ramonski opened this issue Dec 5, 2017 · 2 comments
Closed

AR Add: No sample points are found if a sample type was set #443

ramonski opened this issue Dec 5, 2017 · 2 comments

Comments

@ramonski
Copy link
Contributor

ramonski commented Dec 5, 2017

Steps to reproduce

  • Install Demo Data in a new instance
  • Navigate to the client "Klaymore"
  • Click on the AR Add button
  • Select "Apple Pulp" in the sample type field
  • Click on the Sample point field

Current behavior

No Sample Points are found

Expected behavior

Sample Points with no Sample Type attached are listed

Screenshot (optional)

klaymore__ar_add

@ramonski ramonski self-assigned this Dec 5, 2017
@ramonski
Copy link
Contributor Author

ramonski commented Dec 5, 2017

In the background happens a UnicodeDecodeError, because the queried getSampleTypeTitle is a Keywordindex and fails if unicode strings are in the query.

This unicode transform comes from json.loads:

(Pdb++) json.loads(self.request['base_query'])
{u'getClientUID': [u'a15f9838c95b4d7b873f4790dcd77298', u'0cb4951d905f4672a837a7b3db928405'], u'portal_type': u'SamplePoint', u'inactive_state': u'active', u'getSampleTypeTitle': [u'wm KSS', u'']}

A better approach could be to use ast.literal_eval:

(Pdb++) ast.literal_eval(self.request['base_query'])
{'getClientUID': ['a15f9838c95b4d7b873f4790dcd77298', '0cb4951d905f4672a837a7b3db928405'], 'portal_type': 'SamplePoint', 'inactive_state': 'active', 'getSampleTypeTitle': ['wm KSS', '']}

or a solutions like this one:

https://github.com/senaite/senaite.exporter/blob/master/senaite/exporter/utils/__init__.py#L13

@ramonski
Copy link
Contributor Author

ramonski commented Dec 7, 2017

Tested and it works after applying the Upgrade step 1.1.8

@ramonski ramonski closed this as completed Dec 7, 2017
xispa added a commit that referenced this issue Aug 30, 2018
ast does not convert "null" to python's None and the following
Traceback is thrown:

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.widgets.referencewidget, line 204, in __call__
  Module bika.lims.browser.client.ajax, line 31, in __call__
  Module bika.lims.adapters.referencewidgetvocabulary, line 44, in __call__
  Module ast, line 80, in literal_eval
  Module ast, line 63, in _convert
  Module ast, line 62, in <genexpr>
  Module ast, line 60, in _convert
  Module ast, line 79, in _convert
ValueError: malformed string

ast.literal_eval has been replaced by built-in json.loads, and to
overcome the issue about unicodes:
#443
a function that converts unicodes to strings recursively has been
added, as suggested in the same issue above
ramonski pushed a commit that referenced this issue Aug 31, 2018
ast does not convert "null" to python's None and the following
Traceback is thrown:

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.widgets.referencewidget, line 204, in __call__
  Module bika.lims.browser.client.ajax, line 31, in __call__
  Module bika.lims.adapters.referencewidgetvocabulary, line 44, in __call__
  Module ast, line 80, in literal_eval
  Module ast, line 63, in _convert
  Module ast, line 62, in <genexpr>
  Module ast, line 60, in _convert
  Module ast, line 79, in _convert
ValueError: malformed string

ast.literal_eval has been replaced by built-in json.loads, and to
overcome the issue about unicodes:
#443
a function that converts unicodes to strings recursively has been
added, as suggested in the same issue above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant