Re: QS-RF: maximum recursion depth exceeded in cmp
Thanks, Malcolm, everything works fine now, I just remove 'parent' from ordering! I know about django-mptt, but I do not need tree actually, I just want to view relations... With plain ordering... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: QS-RF: maximum recursion depth exceeded in cmp
> One more thing: What are you doing with class Import? That doesn't make any > sense like that to me. It's for my own purposes. I use it to show that data can be imported into this model and to define clean methods like in newforms to clean and normalise imported data :) class Import: @staticmethod def clean_last_name(value): """In general, any cleaning method can raise ValidationError if there is a problem with the data it is processing, passing the relevant error message to the ValidationError constructor. If no ValidationError is raised, the method should return the cleaned (normalised) data as a Python dict object with field name as key and field value as value.""" # Split last_name to first_name, last_name, middle_name import re pattern = r'(?P[-\w]+) +(?P\w) [. ]*(?P\w?)' regexp = re.compile(pattern, re.U) match = regexp.match(value) if match: last_name, first_name, middle_name = match.groups() return dict(first_name=first_name, last_name=last_name, middle_name=middle_name) else: return dict(last_name=value) @staticmethod def clean_comment(value): """Remove leading '{{' and trailing '}}' chars from comment.""" return dict(comment=value.strip('{}')) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: QS-RF: maximum recursion depth exceeded in cmp
On Tue, 2008-04-15 at 07:59 -0700, sector119 wrote: > Template error > > In template /home/sector119/devel/eps_src/eps/templates/base.html, > error at line 23 > Caught an exception while rendering: maximum recursion depth exceeded > in cmp > > 23{{ user.office.location.get_type_display }}. > 24{{ user.office.location.name }}, > 25{{ user.office.name }}, > > -- > > class Location(models.Model): > id = models.IntegerField(_('Id'), primary_key=True) > parent = models.ForeignKey('self', verbose_name=_('Location parent > id:'), null=True, blank=True, related_name='child_set') > name = models.CharField(_('Location'), help_text=_('Office or > person location.'), max_length=32) > type = models.PositiveSmallIntegerField(_('Location type'), > choices=LOCATION_TYPE_CHOICES) [...] > class Meta: > verbose_name = _('Location') > verbose_name_plural = _('Locations') > ordering = ['parent', 'id'] This is a combination of a bug in your code and a bug in queryset-refactor. It is also something that is specific to queryset-refactor because it fixes a bug in trunk, as noted below. The queryset-refactor bug is now fixed, as of [7429], but all that does is change the error you get. Now it will report that there is an infinite ordering loop in the Location model (it already did this in most cases, but I'd somehow broken the "related to 'self'" case and hadn't realised it was behaving differently). This is a case where queryset-refactor fixes a bug that exists in trunk and thus the results change slightly, but only because trunk was doing it wrong. The problem is that to order by the 'parent' model properly, we need to order those parents by their own parents (since that is the ordering on the parent model as well), which means we need to know how to order the grandparents and then the great-grandparents and so on. And what we don't know until we examine the data is how many levels of ordering are involved here. In short, there is no way to construct an SQL query that will correctly order by parents based on this data structure. Django trunk just orders by the immediate parent, which, as I said, doesn't raise an error, but it also isn't really correct or intuitive. Django queryset-refactor detects the infinite loop problem and reports it as an error. What you can do is order by 'parent_id', which is equivalent to the current trunk behaviour, although it might not really be what you want. That doesn't require joining Location to itself multiple times at the SQL level, since the parent_id value is part of the Location table. But you have to specify that manually, since ordering by ForeignKeys is quite possible, providing there is not an infinite loop and it would be lots of extra work for Django to work out the loop and then change the meaning of the ordering field each time. So you need to get the right in your own code. Alternatively, you need to change your tree-like structure to include a bit more additional information so that ordering of nodes in the tree can be done. This is what django-mptt does and there are also lots of articles around on the Web and in books about how to store tree-like data structures in SQL. Regards, Malcolm -- Honk if you love peace and quiet. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: QS-RF: maximum recursion depth exceeded in cmp
What I am trying to do is reproduce your problem. So I laid out two simple classes: CHOICES = ( (1,'Choice 1'), (2, 'Choice 2') ) class FirstClass(models.Model): parent = models.ForeignKey('self', blank=True, null=True) choicelist = models.PositiveSmallIntegerField(choices=CHOICES) class SecondClass(models.Model): parent = models.ForeignKey('self', blank=True, null=True) choice = models.ForeignKey(FirstClass) in which I am trying to get to the problem. In the shell I am able to see what is going on: >>> a = FirstClass(choicelist=1) >>> a.save() >>> b = SecondClass(choice=a) >>> b.save() >>> b.choice.get_choicelist_display() u'Choice 1' This test does exactly what it is supposed to do. I still am missing what is causing this error. It is most likely happening in a loop of some sort, which is somewhere else in your template. Is there a loop in you template? Go into the shell and try to extract the data from the user object like above. My bet is that that api works exactly like you expect it to. There is something else. Is there anymore traceback? Try to reproduce in the shell, that will help us pinpoint exactly where the error is coming from. One more thing: What are you doing with class Import? That doesn't make any sense like that to me. Also, I realize that the fact that you are using the QS-RF branch is important for us to know what base code you are working from, but this is the second post you have posted that doesn't really have anything specific to that branch. You will get more people to help you out if you leave that out of the subject and mention it inside the body of the message where it becomes apparent that the problem is not QS-RF specific. On Tue, Apr 15, 2008 at 10:59 AM, sector119 <[EMAIL PROTECTED]> wrote: > > Template error > > In template /home/sector119/devel/eps_src/eps/templates/base.html, > error at line 23 > Caught an exception while rendering: maximum recursion depth exceeded > in cmp > > 23 {{ user.office.location.get_type_display }}. > 24 {{ user.office.location.name }}, > 25 {{ user.office.name }}, > > -- > > class Location(models.Model): >id = models.IntegerField(_('Id'), primary_key=True) >parent = models.ForeignKey('self', verbose_name=_('Location parent > id:'), null=True, blank=True, related_name='child_set') >name = models.CharField(_('Location'), help_text=_('Office or > person location.'), max_length=32) >type = models.PositiveSmallIntegerField(_('Location type'), > choices=LOCATION_TYPE_CHOICES) > >def __unicode__(self): >return self.name > >class Import: >pass > >class Meta: >verbose_name = _('Location') >verbose_name_plural = _('Locations') >ordering = ['parent', 'id'] > >class Admin: >pass > > > -- > > class OrganizationOffice(models.Model): >parent = models.ForeignKey('self', verbose_name=_('Parent > office:'), null=True, blank=True) >location = models.ForeignKey(Location, > verbose_name=_('Location:')) >name = models.CharField(_('Office'), max_length=50) >bank = models.CharField(_('Bank'), max_length=50, null=True, > blank=True) >account = fields.PositiveBigIntegerField(_('Account'), null=True, > blank=True) >bic = models.PositiveIntegerField(_('BIC'), help_text=_('Bank > identifier code.'), null=True, blank=True) >code = models.PositiveIntegerField(_('Code'), > help_text=_('Enterprise code.'), null=True, blank=True) >in_testmode = models.BooleanField(_('Office is in test mode'), > default=False) >day_is_open = models.BooleanField(_('Transaction day is open'), > default=False) > >def __unicode__(self): >return self.name > >class Import: >pass > >class Meta: >verbose_name = _('Office') >verbose_name_plural = _('Offices') >ordering = ['location', 'parent', 'id'] > >class Admin: >search_fields = ('^id', '^location__name', 'name') > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: QS-RF: maximum recursion depth exceeded in cmp
Template error In template /home/sector119/devel/eps_src/eps/templates/base.html, error at line 23 Caught an exception while rendering: maximum recursion depth exceeded in cmp 23 {{ user.office.location.get_type_display }}. 24 {{ user.office.location.name }}, 25 {{ user.office.name }}, -- class Location(models.Model): id = models.IntegerField(_('Id'), primary_key=True) parent = models.ForeignKey('self', verbose_name=_('Location parent id:'), null=True, blank=True, related_name='child_set') name = models.CharField(_('Location'), help_text=_('Office or person location.'), max_length=32) type = models.PositiveSmallIntegerField(_('Location type'), choices=LOCATION_TYPE_CHOICES) def __unicode__(self): return self.name class Import: pass class Meta: verbose_name = _('Location') verbose_name_plural = _('Locations') ordering = ['parent', 'id'] class Admin: pass -- class OrganizationOffice(models.Model): parent = models.ForeignKey('self', verbose_name=_('Parent office:'), null=True, blank=True) location = models.ForeignKey(Location, verbose_name=_('Location:')) name = models.CharField(_('Office'), max_length=50) bank = models.CharField(_('Bank'), max_length=50, null=True, blank=True) account = fields.PositiveBigIntegerField(_('Account'), null=True, blank=True) bic = models.PositiveIntegerField(_('BIC'), help_text=_('Bank identifier code.'), null=True, blank=True) code = models.PositiveIntegerField(_('Code'), help_text=_('Enterprise code.'), null=True, blank=True) in_testmode = models.BooleanField(_('Office is in test mode'), default=False) day_is_open = models.BooleanField(_('Transaction day is open'), default=False) def __unicode__(self): return self.name class Import: pass class Meta: verbose_name = _('Office') verbose_name_plural = _('Offices') ordering = ['location', 'parent', 'id'] class Admin: search_fields = ('^id', '^location__name', 'name') --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: QS-RF: maximum recursion depth exceeded in cmp
Could you post your models code somewhere for us to take a look at? Also could you separate each variable in you template to a different line so we know what exactly was causing the error? I think I have an idea of what is going on here, but I want to try to reproduce it with as few lines as possible. On Tue, Apr 15, 2008 at 10:16 AM, sector119 <[EMAIL PROTECTED]> wrote: > > I begin testing qs-rf branch and get this exception, why? > May be because Office model is tree - has parent = > models.ForeignKey('self') field? > > Exception Type: RuntimeError > Exception Value:maximum recursion depth exceeded in cmp > Exception Location: /home/sector119/devel/django_src/django/db/models/ > sql/query.py in join, line 734 > Python Executable: /usr/bin/python2.5 > > > Template error > > In template /home/sector119/devel/eps_src/eps/templates/base.html, > error at line 23 > Caught an exception while rendering: maximum recursion depth exceeded > in cmp > > 23 {{ user.office.location.get_type_display }}. > {{ user.office.location.name }}, {{ user.office.name }}, {% firstof > user.get_full_name user.username %} | {% block userlinks %} href="">{% trans 'Help' %} | {% trans 'Sign out' %}{% > endblock %} > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
QS-RF: maximum recursion depth exceeded in cmp
I begin testing qs-rf branch and get this exception, why? May be because Office model is tree - has parent = models.ForeignKey('self') field? Exception Type: RuntimeError Exception Value:maximum recursion depth exceeded in cmp Exception Location: /home/sector119/devel/django_src/django/db/models/ sql/query.py in join, line 734 Python Executable: /usr/bin/python2.5 Template error In template /home/sector119/devel/eps_src/eps/templates/base.html, error at line 23 Caught an exception while rendering: maximum recursion depth exceeded in cmp 23 {{ user.office.location.get_type_display }}. {{ user.office.location.name }}, {{ user.office.name }}, {% firstof user.get_full_name user.username %} | {% block userlinks %}{% trans 'Help' %} | {% trans 'Sign out' %}{% endblock %} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---