#29697: Complex query crashes with "missing FROM-clause entry for table"
-------------------------------------+-------------------------------------
     Reporter:  Dmitry               |                    Owner:  Can
                                     |  Sarıgöl
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Can Sarıgöl):

 Hello. I guess the problem is in trim start function. I want to change
 this code like above. What do you think?


 {{{
 class Query:
     """A single SQL query."""
     ...

    def trim_start(self, names_with_path):
        ...
        lookup_tables = [
             t for t in self.alias_map
             if t in self._lookup_joins or t == self.base_table
         ]
         # from_opts_tables for manage to define unref_alias table.
         # before unref, make sure the table wasn't added
         # in another from_opts as reference.
         **from_opts_tables = [path.from_opts.db_table for path in
 all_paths]**
         for trimmed_paths, path in enumerate(all_paths):
             ...
             # is the alias exists in another from_opts?
             **if not alias in from_opts_tables:**
                 self.unref_alias(alias)
         ...
         if self.alias_map[lookup_tables[trimmed_paths + 1]].join_type !=
 LOUTER:
            ....
            **if not lookup_tables[trimmed_paths] in from_opts_tables:**
                self.unref_alias(lookup_tables[trimmed_paths])

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29697#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.41db7ff5463cd69c57e09e392a47578f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to