-
Notifications
You must be signed in to change notification settings - Fork 313
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
Array types creates extra (and unneeded) type for the array items #570
Comments
This seems to boil down to this behaviour wrt. customize: $ python
Python 2.7.12 (default, Nov 4 2017, 00:30:53)
>>> import decimal
>>> from spyne import Uuid
>>> from spyne.model.primitive import Unicode
>>>
>>> UnboundedUnicode = Unicode.customize(max_occurs=decimal.Decimal("inf"))
>>> UnboundedUnicode.is_default(UnboundedUnicode)
True
>>> UnboundedUUID = Uuid.customize(max_occurs=decimal.Decimal("inf"))
>>> UnboundedUUID.is_default(UnboundedUUID)
False
>>> DemoType = Unicode(type_name="DemoType", pattern="demo")
>>> UnboundedDemoType = DemoType(max_occurs=decimal.Decimal("inf"))
>>> UnboundedDemoType.is_default(UnboundedDemoType)
False When defining a type by assigning DemoArray = Array(DemoType) the item type is customized under the hood by this code: # hack to default to unbounded arrays when the user didn't specify
# max_occurs.
if serializer.Attributes.max_occurs == 1:
serializer = serializer.customize(max_occurs=decimal.Decimal('inf')) Apart from this making no sense to me because it does not compose (making an array of some type with max_occurs=3 will drop that max_occurs, but I think this is broken in XML Schema already), this leads to the creation of a new type name in customize due to this code: retval = type(cls_name, cls_bases, cls_dict)
if not retval.is_default(retval):
retval.__extends__ = cls
... I'd imagine this basically hinders reuse of any custom type in arrays. IMHO the method |
First, thanks a lot for digging. It seems that the WSDL output is not strictly wrong but suboptimal and could be fixed (hence the enhancement flag). Would you agree?
That's by design. is_default is supposed to compare a given type to its root type, not its immediate base type.
Again, this is by design. |
Instead of looking at the model subsystem, I think we should look at the xml schema subsystem. In the xml schema world, there are two types of customizations: stuff like The strategy here should be to distinguish between these two types of customizations and replace types that only have element-level customizations (compared to its immediate base, not its root) while generating the xml schema. Here's the entry point, which should end up calling spyne/spyne/interface/xml_schema/_base.py Line 117 in 049b789
|
AFAICT this I am not sure though if that information has to be channeled back from the XML layer - I would expect that to be required. My approach was to improve is_default to actually detect if a customized type is essentially the same as the original type. This fixed my issue but makes a number of other tests fail. |
Instead of messing with is_default, you should implement the same test in the xml schema generator so that it ignores the "duplicate" type and uses the original one. |
I have encountered the same problem. How do you solve it in the end? |
We forked at spyne 2.9.3 and ported it to Python 3 ourselves (at least in so far that our unit and integration tests are running). As we are no longer required to use SOAP as the communication protocol we are slowly moving away from spyne. It has a lot of magic that has little benefit to us as we will have a single RESTful interface. But we may return to spyne in case some client dictates that we have to support another protocol again. Full disclosure: We started with using soaplib as it appeared to be the best soap library for Python on the server side. We migrated to rpclib and later spyne still using only the soap part. |
I slove the problem by http://spyne.io/docs/2.10/manual/03_types.html#arrays |
Deriving
Array(DemoType)
from a given typeDemoType
creates an unneededDemoTypeArray_DemoTypeType
for the items of the array.I created a simple test for this and used git bisect to identify the commit which caused this change in behaviour. The change was in e162935.
Here is the code to demonstrate this:
Driving shell script:
Expected output (like in spyne 2.9.3):
Actual output (in spyne 2.12.14):
The text was updated successfully, but these errors were encountered: