title: python suds wrong namespace prefix in SOAP request
body: <p>I use python/suds to implement a client and I get wrong namespace prefixes in the sent SOAP header for a spefic type of parameters defined by <code>element ref=</code> in the wsdl. </p>
  
  <p>The  .wsdl is referencing a data types  .xsd  file, see below. The issue is with the function <code>GetRecordAttributes</code> and its first argument of type <code>gbt:recordReferences</code>.</p>
  
  <p><strong>File:  browse2.wsdl</strong></p>
  
  <pre><code>&lt;xsd:schema targetNamespace="http://www.grantadesign.com/10/10/Browse" xmlns="http://www.grantadesign.com/10/10/Browse" xmlns:gbt="http://www.grantadesign.com/10/10/GrantaBaseTypes" elementFormDefault="qualified" attributeFormDefault="qualified"&gt;
  &lt;xsd:import schemaLocation="grantabasetypes2.xsd" namespace="http://www.grantadesign.com/10/10/GrantaBaseTypes"/&gt;
  &lt;xsd:element name="GetRecordAttributes"&gt;
        &lt;xsd:complexType&gt;
            &lt;xsd:sequence&gt;
                &lt;xsd:element ref="gbt:recordReferences"&gt;
                &lt;/xsd:element&gt;
  </code></pre>
  
  <p><strong>Referenced File :  grantabasetypes2.xsd</strong></p>
  
  <pre><code>&lt;element name="recordReferences"&gt;
    &lt;complexType&gt;
      &lt;sequence&gt;
        &lt;element name="record" minOccurs="0" maxOccurs="unbounded" type="gbt:MIRecordReference"/&gt;
      &lt;/sequence&gt;
    &lt;/complexType&gt;
  &lt;/element&gt;
  </code></pre>
  
  <p><strong>SOAP Request sent by suds:</strong></p>
  
  <pre><code>&lt;SOAP-ENV:Envelope xmlns:ns0="http://www.grantadesign.com/10/10/GrantaBaseTypes" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www.grantadesign.com/10/10/Browse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;SOAP-ENV:Header/&gt;
     &lt;ns1:Body&gt;
        &lt;ns2:GetRecordAttributes&gt;
           &lt;ns2:recordReferences&gt;
              &lt;ns0:record&gt;
              &lt;/ns0:record&gt;
           &lt;/ns2:recordReferences&gt;
        &lt;/ns2:GetRecordAttributes&gt;
     &lt;/ns1:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p><strong>Problem</strong> :  <code>&lt;ns2:recordReferences&gt;</code> has wrong prefix, should be  <code>&lt;ns0:recordReferences&gt;</code> since it belongs to the namespace <code>...GrantaBaseTypes</code>  defined in the .xsd.  </p>
  
  <p>This happens for all arguments defined by <code>ref=</code> in the wsdl. How can this be automatically fixed?</p>
  
  <p>Note: I checked that the "good" prefix is accepted by the service by manually sending the xml SOAP request via curl. </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I meddled with SUDS source code and the following empirical fix forces all elements with <code>ref=</code> attribute  to assume the ref-ed namespace (previously, they take on the schema root namespace or whatever <code>tns</code> is):</p>
  
  <p>File: /suds/xsd/sxbase.py</p>
  
  <pre><code>class SchemaObject(object):
  ....
      def namespace(self, prefix=None):
  
          ns = self.schema.tns
  
  #FIX BEGIN
          if self.ref and self.ref in self.schema.elements.keys():
              ns = self.ref
  #FIX END
  </code></pre>
  
  <p>Works with my service, but I'm not sure if it'll break other things. I would prefer a smarter solution that does not change SUDS source code. </p>
  
  <p>Thanks, </p>
  
  <p>Alex</p>