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

Cannot convert string value 1.1 at position 1 for the field RFCFLOAT to type RFCTYPE_FLOAT #142

Closed
guettli opened this issue Nov 4, 2019 · 5 comments

Comments

@guettli
Copy link
Contributor

guettli commented Nov 4, 2019

This snippet works:

# -*- coding: utf-8 -*
from __future__ import absolute_import, division, print_function, unicode_literals

from pyrfc import Connection

conn = Connection(...)

#import django
#django.setup()

result = conn.call(b'STFC_STRUCTURE', **{"IMPORTSTRUCT": {"RFCFLOAT": 1.1}})
print(result)

But if I uncomment the two django-lines, then it fails with this exception:

Traceback (most recent call last):
  File "tmp/float-error.py", line 11, in <module>
    result = conn.call(b'STFC_STRUCTURE', **{"IMPORTSTRUCT": {"RFCFLOAT": 1.1}})
  File "src/pyrfc/_pyrfc.pyx", line 415, in pyrfc._pyrfc.Connection.call
  File "src/pyrfc/_pyrfc.pyx", line 1650, in pyrfc._pyrfc.fillFunctionParameter
  File "src/pyrfc/_pyrfc.pyx", line 1700, in pyrfc._pyrfc.fillVariable
  File "src/pyrfc/_pyrfc.pyx", line 1662, in pyrfc._pyrfc.fillStructureField
  File "src/pyrfc/_pyrfc.pyx", line 1805, in pyrfc._pyrfc.fillVariable
pyrfc._exception.ExternalRuntimeError: RFC_CONVERSION_FAILURE (rc=22): key=RFC_CONVERSION_FAILURE, message=Cannot convert string value 1.1 at position 1 for the field RFCFLOAT to type RFCTYPE_FLOAT [MSG: class=, type=, number=, v1-4:=;;;]

Python 2.7

This is very strange, since importing django and calling django.setup() should not have any side-effects.

I am running the latest version of PyRFC (master from github).

@bsrdjan
Copy link
Member

bsrdjan commented Nov 4, 2019

I could not reproduce with clean django settings:

import django # v 1.11.26 
from django.conf import settings
settings.configure()
django.setup()

print(pyrfc.__version__)

Could you please check if the issue happens with default django settings, like above?

If default settings works, I would start from activating your django application settings step by step, to localise the root cause.

@guettli
Copy link
Contributor Author

guettli commented Nov 4, 2019

I found what influences the way pyRFC works: locale

Insteand of importing django there is a simple way to force the error:

import locale
locale.setlocale(locale.LC_ALL, b'de_DE.UTF-8')

I hope you can reproduce it now.

I would suggest pyRFC avoids using the locale.

I hate the locale. I wrote my anger down, in the hope other will avoid it from scratch: https://github.com/guettli/programming-guidelines/blob/master/README.md#avoid-posix-locale

@guettli
Copy link
Contributor Author

guettli commented Nov 8, 2019

@bsrdjan Hi Sdrjan could you reproduce the error after setting the locale?

@bsrdjan
Copy link
Member

bsrdjan commented Nov 13, 2019

Could you please check if the fix, works for your use-case? Float and Decimal are always accepted and strings only when decimal separator is correct, for the application locale. Grouping separators are not supported, application should handle.

Unit tests: test_datatypes.py#L618

@guettli
Copy link
Contributor Author

guettli commented Nov 19, 2019

@bsrdjan yes, I installed pyrfc from git master and the float issue is gone now. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants