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

xs:int value filled with "1.0" (expected: "1") #1361

Open
fvkluck opened this issue Feb 17, 2023 · 1 comment
Open

xs:int value filled with "1.0" (expected: "1") #1361

fvkluck opened this issue Feb 17, 2023 · 1 comment

Comments

@fvkluck
Copy link

fvkluck commented Feb 17, 2023

Hi,

First of all, thanks for creating and maintaining python-zeep.

Recently at work I ran into an issue where an xs:int typed value ended up filled as "1.0". This seems to me incorrect, and the little exact specification I could find on the internet seems to agree that the decimal point should not be a part of the int (e.g. here). We're on zeep version 4.2.1.

I've looked into the source code, and I think I've found the source of this behavior here:

class Integer(Decimal):
    _default_qname = xsd_ns("integer")
    accepted_types = [int, float, str]

    def xmlvalue(self, value):
        return str(value)

    def pythonvalue(self, value):
        return int(value)

The accepted python types for the xs:int are the int, float and str (makes sense), but then it is transformed into xml using 'just' str(value).

If you agree with the analysis, I think I can find the time to create a PR (including a minimal example/test). So some questions:

  1. Do you agree that the "1.0" should be a "1" for type xs:int?
  2. Do you have a preference for the behavior regarding xs:int's being filled from floats? Some ideas I have:
    a. Raise an error (reasoning: it's better for the consumer of the library to actively decide how to transform the float into an int)
    b. Just cast it to an int first (reasoning: most likely the value is correct, and it's just the type that's incorrect)
    Personally I lean towards idea a.

If you can let me know if it's worth spending time on (i.e. a PR would have a chance of being accepted), I'll start experimenting locally and fixing it.

Best,
Florian

@fvkluck
Copy link
Author

fvkluck commented Feb 17, 2023

I just realised that both of my suggestions could be considered breaking changes, and would ruin the fun for anyone relying on the float getting an xmlvalue of "1.0" instead of "1". Or anyone that sends the soap request to a service that doesn't mind the "1.0".

The issue feels a bit minor for a breaking change.

So then I guess the ideas I have are:
c. keep current behavior, but log a warning
d. Introduce a setting/feature flag that enables this behavior and defaults to False. But that's a lot of work + additional maintenance for this issue
e. Do nothing

c and e seem the only reasonable ones

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

1 participant