Skip to content
Browse files

Avoid endless recursion when collecting objects -- really this shouldn't

happen unless there's a cycle in your model dependencies which would
indicate bigger problems.
  • Loading branch information...
1 parent d3f7f27 commit ac900c23f8db1f448f0954d35346bb7dc63c600d @coleifer committed Apr 6, 2012
Showing with 6 additions and 4 deletions.
  1. +6 −4 peewee.py
View
10 peewee.py
@@ -2537,11 +2537,13 @@ def collect_models(cls, accum=None):
for related_name, rel_model in cls._meta.reverse_relations.items():
rel_field = cls._meta.get_field_for_related_name(rel_model, related_name)
- coll = [(rel_model, rel_field.name, rel_field.null)] + accum
- if not rel_field.null:
- models.extend(rel_model.collect_models(coll))
+ group = (rel_model, rel_field.name, rel_field.null)
+ if group not in accum:
+ coll = [group] + accum
+ if not rel_field.null:
+ models.extend(rel_model.collect_models(coll))
- models.append(coll)
+ models.append(coll)
return models
def collect_queries(self):

0 comments on commit ac900c2

Please sign in to comment.
Something went wrong with that request. Please try again.