Code

Opened 5 years ago

Closed 3 years ago

Last modified 3 years ago

#11474 closed (duplicate)

models.XMLField doesn't work as advertised

Reported by: garrison Owned by: nobody
Component: Documentation Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

There are two errors currently in the (documentation of) models.XMLField:

  • The documentation claims that schema_path is a required argument, but it is not.
  • Regardless of whether schema_path is given, models.XMLField does not actually perform any validation. It works no differently than an ordinary TextField, succeeding even if the input is not XML at all.

Tickets #3094 and #5620 are likely related to this bug. I reference them for historical interest, since it seems that it was once assumed that #3094 would to be fixed before 1.0.

Attachments (0)

Change History (5)

comment:1 Changed 5 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by django@…

As a stopgap measure, xml.parsers.expat could be used to verify that the XML is at least well-formed, albeit perhaps not compliant with any particular schema.

For example, I currently use the following on a form that allows users to input XML in a multi-line text field:

    def clean_dialplan_xml(self):
        from xml.parsers import expat
        tmp = expat.ParserCreate()

        try:
            tmp.Parse(self.cleaned_data['dialplan_xml'])
        except expat.ExpatError, e:
            raise forms.ValidationError(e)

        return self.cleaned_data['dialplan_xml']

This could/should perhaps be instead implemented in django.db.models.fields instead.

comment:3 Changed 3 years ago by PaulM

  • Component changed from Database layer (models, ORM) to Documentation
  • milestone set to 1.3

This is really a docs ticket. I'm changing the category to reflect that, so that it'll get some attention.

#3094 will be resolved whenever it gets resolved (if ever) but in the meantime the docs should reflect the way Django really functions (especially for 1.1 and 1.2 where the feature will never surface).

I suggest changing the relevant docs to read something like:

A TextField for XML. Does not currently provide any validation. Takes one optional argument:

schema_path
The filesystem path to an XML schema.

In addition to posting here, I'll try and get that ticket moving as well.

comment:4 Changed 3 years ago by gabrielhurley

  • Resolution set to duplicate
  • Status changed from new to closed

Closing as a duplicate of #3094. There's no point in changing the docs until that ticket is resolved. My thoughts on what the resolution should be are noted on that ticket.

comment:5 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.