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

TypeError: 'name' (string) should be from 1-30 chars. #115

Closed
guettli opened this issue Oct 2, 2019 · 12 comments
Closed

TypeError: 'name' (string) should be from 1-30 chars. #115

guettli opened this issue Oct 2, 2019 · 12 comments

Comments

@guettli
Copy link
Contributor

guettli commented Oct 2, 2019

I use clientPrintDescription.py for introspection a RFC function module.

But I get this result:

 python clientPrintDescription.py /FOO/BAR

Traceback (most recent call last):
  File "clientPrintDescription.py", line 84, in <module>
    main(sys.argv[1])
  File "clientPrintDescription.py", line 26, in main
    func_desc = connection.get_function_description(function_name)
  File "src/pyrfc/_pyrfc.pyx", line 360, in pyrfc._pyrfc.Connection.get_function_description
  File "src/pyrfc/_pyrfc.pyx", line 1943, in pyrfc._pyrfc.wrapFunctionDescription
  File "src/pyrfc/_pyrfc.pyx", line 1904, in pyrfc._pyrfc.wrapTypeDescription
  File "src/pyrfc/_pyrfc.pyx", line 1011, in pyrfc._pyrfc.TypeDescription.add_field
TypeError: 'name' (string) should be from 1-30 chars.

The script works fine for several other RFC function modules.

What could be wrong here?

I guess the client code is all right, but there is something broken with this rfc function module.

@bsrdjan
Copy link
Contributor

bsrdjan commented Oct 2, 2019

It looks like the field name empty or longer than 30 chars is detected in function module metadata, triggering the exception.

Could you please try to find the suspicious field in function module parameters ? Is it a big function module, could you eventually somehow post/dump the structure here?

@guettli
Copy link
Contributor Author

guettli commented Oct 2, 2019

Thank you for your fast reply. Is there an equivalent to python clientPrintDescription.py /FOO/BAR which I can execute inside SAP?

Here is the head of the function module:

FUNCTION /MLK/TABLES_OF_CURRENT_USER.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  EXPORTING
*"     VALUE(ALLOWED_TABLES) TYPE  /MLK/TT_TABNAME
*"----------------------------------------------------------------------

Details of /MLK/TT_TABNAME

grafik

grafik

Please tell me, if you need more info.

@guettli
Copy link
Contributor Author

guettli commented Oct 2, 2019

if the length of the name would get checked earlier, it would be possible to provide a better error message. It would be nice to see /MLK/TT_TABNAME in the error message.

Lines around line number 1904

    rc = RfcGetTypeName(typeDesc, typeName, &errorInfo)
    if rc != RFC_OK:
        raise wrapError(&errorInfo)
    name = wrapString(typeName)

@bsrdjan
Copy link
Contributor

bsrdjan commented Oct 2, 2019

Yes, the error message can be improved. I reproduced with EXPORTING TABLE TYPE parameter and need to investigate. SAP internal alternatives are two function modules:

RFC_METADATA_GET, for reading RFC parameters metadata (add /MLK/TABLES_OF_CURRENT_USER to FUNCTIONNAMES)

and:

DDIF_FIELDINFO_GET (/MLK/TT_TABNAME goes into TABNAME)

Both are strictly internal and undocumented, requiring considerable amount of try & error for any bigger use.

Another alternative is using corresponding functionality of Java JCo or NET NCo.

@guettli
Copy link
Contributor Author

guettli commented Oct 2, 2019

Fortunately I am not under pressure. If you are able to provide a fix in roughly one week, I can develop other stuff until next week.

Since you can reproduce it, I guess you are not far away from a fix?

@guettli
Copy link
Contributor Author

guettli commented Oct 2, 2019

BTW, I don't think switching the language makes much sense. Python is very popular. Java and C# share are in decline:

grafik

@guettli
Copy link
Contributor Author

guettli commented Oct 2, 2019

BTW: The example code of this project works. But, they code does not look like Python. It looks like someone translated code from a different language line-by-line to python.

I would suggest that SAP makes a contract with a python freelancer (not me) to clean up. The code could be simplified a lot.

Python developers care for beauty/simple code.

@guettli
Copy link
Contributor Author

guettli commented Oct 2, 2019

BTW3: I wrote down some thoughts while learning SAP+ABAP. I like the SAP platform. But I like the new development environments, too: https://github.com/guettli/why-i-like-django-and-sap/blob/master/README.md Feedback is welcome.

@bsrdjan bsrdjan closed this as completed in 387e946 Oct 4, 2019
@bsrdjan
Copy link
Contributor

bsrdjan commented Oct 4, 2019

Fixed in 387e946, by removing zero length field name check: https://github.com/SAP/PyRFC/blob/master/src/pyrfc/_pyrfc.pyx#L1025. Will be added to next release.

@bsrdjan
Copy link
Contributor

bsrdjan commented Oct 4, 2019

BTW: The example code of this project works. But, they code does not look like Python. It looks like someone translated code from a different language line-by-line to python.

I would suggest that SAP makes a contract with a python freelancer (not me) to clean up. The code could be simplified a lot.

Python developers care for beauty/simple code.

Examples are not a part of PyRFC maintained codebase, only the RFC Client functionality. Agree that the code in examples folder could be improved and that can be done once the Server and other functionalities are added to PyRFC. I mentioned NCo and JCo only to provide a complete answer, didn't want to suggest moving away from Python to Java/NET :)

bsrdjan added a commit that referenced this issue Oct 4, 2019
@guettli
Copy link
Contributor Author

guettli commented Oct 7, 2019

@bsrdjan do you know when there will be a new release which contains this bug fix?

@bsrdjan
Copy link
Contributor

bsrdjan commented Oct 8, 2019

Hopefully next week, together with DECF types added.

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