henriquebastos / django-aggregate-if

Conditional aggregates for Django queries, just like the famous SumIf and CountIf in Excel.
MIT License
137 stars 17 forks source link

Django1.7 compatibility - query.promote_joins() changes #8

Closed end0 closed 10 years ago

end0 commented 10 years ago

It seems that this packages is pretty well adjusted for Django1.7, except for an issue with the query.promote_joins() method.

I'm not 100% sure, but it appears that in Django1.6, promote_joins allows for an unconditional kwarg to be passed:

def promote_joins(self, aliases, unconditional=False):
    """
    Promotes recursively the join type of given aliases and its children to
    an outer join. If 'unconditional' is False, the join is only promoted if
    it is nullable or the parent join is an outer join.

    Note about join promotion: When promoting any alias, we make sure all
    joins which start from that alias are promoted, too. When adding a join
    in join(), we make sure any join added to already existing LOUTER join
    is generated as LOUTER. This ensures we don't ever have broken join
    chains which contain first a LOUTER join, then an INNER JOIN, that is
    this kind of join should never be generated: a LOUTER b INNER c. The
    reason for avoiding this type of join chain is that the INNER after
    the LOUTER will effectively remove any effect the LOUTER had.
    """

but in Django1.7, this kwarg is removed:

def promote_joins(self, aliases):
    """
    Promotes recursively the join type of given aliases and its children to
    an outer join. If 'unconditional' is False, the join is only promoted if
    it is nullable or the parent join is an outer join.

    The children promotion is done to avoid join chains that contain a LOUTER
    b INNER c. So, if we have currently a INNER b INNER c and a->b is promoted,
    then we must also promote b->c automatically, or otherwise the promotion
    of a->b doesn't actually change anything in the query results.
    """

aggregate_if.py seems to choke on this at line 122

# Django 1.5+
    if hasattr(query, 'promote_joins'):
        query.promote_joins(join_list, True)

Removing the True arg seems to make it work, but I'm not sure if it passes all the relevant tests...

henriquebastos commented 10 years ago

The branch django-1.7 is well evolved. There's 1 failing test blocking the new release.

I didn't had the time to investigate it any further. Any help is very welcome.

If you're on a hurry you can:

pip install git+https://github.com/henriquebastos/django-aggregate-if.git@django-1.7