bugGNU Health - Bugs: bug #64414, Federation Queue Manager can not...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #64414: Federation Queue Manager can not show no-ascii properly.

Submitter:  Feng Shu <tumashu>
Submitted:  Wed 12 Jul 2023 01:18:26 AM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Ready For Test
Privacy:  Public Assigned to:  meanmicio
Open/Closed:  Open Release:  4.3.0
Module:  health_federation Component:  Hospital Management

Mon 07 Aug 2023 03:11:06 AM UTC, comment #5: 

I have added args_preview field, I think it should solve most issues about no-ascii.

https://hg.savannah.gnu.org/hgweb/health/rev/4023258d35ee

Feng Shu <tumashu>
Mon 17 Jul 2023 06:54:52 PM UTC, comment #4: 

Maybe... it's been a while since I hit that issue with non-ascii chars going through flask / thalamus that led me go with the default ensure_ascii=True

The number of threads on this topic is quite significant, so I would say let's keep it the way it is by now, until there is consensus and, probably even better, when the default value for json.dumps is False.

Bests,
Luis

Luis Falcon <meanmicio>
Group administrator
Mon 17 Jul 2023 03:28:28 AM UTC, comment #3: 


comment #2:

> Revert changeset 5888:6a0a46ff3791
> https://hg.savannah.gnu.org/hgweb/health/rev/336e36474d34
>
> We should keep it as str. There is a logic about using ensure_ascii=True, so it makes sure it always returns a string, instead of a unicode object. To the human eye the raw string might look strange, but its represntation in reports and packages will be the correct one.


ensure_ascii=False seem to return a string too.

  >>> json.dumps(a)
  '{"a": "\\u4f60\\u597d"}'
  >>> json.dumps(a, ensure_ascii=False)
  '{"a": "你好"}'
  >>> type(json.dumps(a, ensure_ascii=False))
  <class 'str'>
  >>> 





>
> Thalamus (and Python in general) parses the unicode escaped strings properly, so we should keep it like this for now, until we're sure unicode objects are properly handled in every instance.


I think it maybe not hard, for:

we use ensure_ascii=False when we create args field of FederationQueue
object.

but, when we send federation queue object to Thalamus, we will do the
following two steps in send_record, so we alway send unicode escaped
strings to thalamus.

1. json.loads(record.args)
2. json.dumps(vals)

-----------------------------------------------------
 def send_record(cls, record):
        ...
        if (record.method == 'PATCH'):
            if (record.federation_locator):
                # [{resource, fields[{name, value}]
                for arg in json.loads(record.args):
                           -------------------------------
                    ...
                    send_data = requests.request(
                        'PATCH', url,
                        data=json.dumps(vals),
                        -----------------------------------
                        auth=(user, password), verify=verify_ssl)

                        ...

------------------------------------------------------

json.loads work well when ensure_ascii=False:


>
> $python3
> Python 3.9.17 (main, Jun 22 2023, 01:13:35)
> [Clang 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a on freebsd13
> Type "help", "copyright", "credits" or "license" for more information.
> >>> print("\u738b\u4e00\u5200")
> 王一刀
>
> Thanks!
> Luis
>
>

Feng Shu <tumashu>
Fri 14 Jul 2023 06:07:07 PM UTC, comment #2: 

Revert changeset 5888:6a0a46ff3791
https://hg.savannah.gnu.org/hgweb/health/rev/336e36474d34

We should keep it as str. There is a logic about using ensure_ascii=True, so it makes sure it always returns a string, instead of a unicode object. To the human eye the raw string might look strange, but its represntation in reports and packages will be the correct one.

Thalamus (and Python in general) parses the unicode escaped strings properly, so we should keep it like this for now, until we're sure unicode objects are properly handled in every instance.

$python3
Python 3.9.17 (main, Jun 22 2023, 01:13:35)
[Clang 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a on freebsd13
Type "help", "copyright", "credits" or "license" for more information.

>>> print("\u738b\u4e00\u5200")

王一刀

Thanks!
Luis


Luis Falcon <meanmicio>
Group administrator
Wed 12 Jul 2023 01:19:49 AM UTC, comment #1: 
Feng Shu <tumashu>
Wed 12 Jul 2023 01:18:26 AM UTC, original submission:  

For example:

{"resource": "people", "fields": [{"name": "name", "value": "\u738b\u4e00\u5200"}, {"name": "lastname", "value": ""}, {"name": "dob", "value": "2001-06-25"}, {"name": "gender", "value": "m"}, {"name": "id", "value": ""}]}]

Feng Shu <tumashu>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by meanmicio (Posted a comment)
  • -email is unavailable- added by tumashu (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-08-11 meanmicio Release4.2.0 4.3.0
    2023-08-11 meanmicio StatusInvalid Ready For Test
    2023-07-14 meanmicio StatusReady For Test Invalid
        Assigned toNone meanmicio
        ReleaseNone 4.2.0
    2023-07-12 tumashu StatusNone Ready For Test

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code