Opened 10 years ago

Closed 9 years ago

#3638 closed (invalid)

loading python fixtures is broken

Reported by: donlaverty Owned by: nobody
Component: Testing framework Version: master
Severity: Keywords: fixture
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by Malcolm Tredinnick)

Reproduce:
Use this fixture:

[{"pk": "1", "model": "main.category", "fields": {"link_name": "all", "name": "\/", "parent": null, "description": ""}}, {"pk": "2", "model": "main.category", "fields": {"link_name": "accessoires", "name": "Accessoires", "parent": 1, "description": ""}}, {"pk": "3", "model": "main.category", "fields": {"link_name": "art_and_design", "name": "Art & Design", "parent": 1, "description": ""}}]

with this model:

class Category(models.Model):
    class Admin:
        pass

    class Meta:
        ordering =['name']

    name        = models.CharField(maxlength=50)
    link_name   = models.SlugField(unique=True)
    description = models.TextField(blank=True)
    parent      = models.ForeignKey('self',blank=True,null=True)

    
    def tree(self,tree=[]):
        tree.append( self )
        children = self.category_set.all()
        child_tree = []
        for c in children:
            if c.name != '/':
                c.tree(child_tree)
        if not child_tree == []:
            tree.append(child_tree)
        return tree

    def link(self):
        return str(self)[2:]

    def __str__(self):
        if not self.parent  :
            return self.name
        return str(self.parent) + '/' + self.name

now try to load it via syncdb

(while you are at it you could clarify in the documentation that python fixtures need to carry the extension .python

Change History (5)

comment:1 Changed 10 years ago by anonymous

Component: Core frameworkUnit test system
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 10 years ago by donlaverty

sorry, i ignored the wiki syntax - my ticket is barely readable - so once more:

Reproduce:

Use this fixture:

[{"pk": "1", "model": "main.category", "fields": {"link_name": "all", "name": "\/", "parent": null, "description": ""}}, {"pk": "2", "model": "main.category", "fields": {"link_name": "accessoires", "name": "Accessoires", "parent": 1, "description": ""}}, {"pk": "3", "model": "main.category", "fields": {"link_name": "art_and_design", "name": "Art & Design", "parent": 1, "description": ""}}]

with this model:

class Category(models.Model):
    class Admin:
        pass

    class Meta:
        ordering =['name']

    name        = models.CharField(maxlength=50)
    link_name   = models.SlugField(unique=True)
    description = models.TextField(blank=True)
    parent      = models.ForeignKey('self',blank=True,null=True)

    
    def tree(self,tree=[]):
        tree.append( self )
        children = self.category_set.all()
        child_tree = []
        for c in children:
            if c.name != '/':
                c.tree(child_tree)
        if not child_tree == []:
            tree.append(child_tree)
        return tree

    def link(self):
        return str(self)[2:]

    def __str__(self):
        if not self.parent  :
            return self.name
        return str(self.parent) + '/' + self.name

now try to load it via syncdb

(while you are at it you could clarify in the documentation that python fixtures need to carry the extension .python

comment:3 Changed 10 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedAccepted

comment:4 Changed 10 years ago by Malcolm Tredinnick

Description: modified (diff)

comment:5 Changed 9 years ago by mssnlayam@…

Resolution: invalid
Status: newclosed

This bug is invalid. The python serializer is not intended for general consumption. http://www.djangoproject.com/documentation/serialization/#serialization-formats

Note: See TracTickets for help on using tickets.
Back to Top