henriquebastos / django-aggregate-if

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

Fix for Django 1.7 #11

Closed henriquebastos closed 9 years ago

henriquebastos commented 10 years ago

@trbs, @end0, @owais, @kawa-marcin,

I've applied the suggested patches to fix the call to promote_joins in Django 1.7.

I've also updated travis and tox scripts to include Django's new version.

However due to Django's new AppConfig boot sequence, the tests are not running on Django 1.7.

py34-django1.7-postgres runtests: commands[1] | python runtests.py --settings tests.test_postgres
Creating test database for alias 'default'...
Traceback (most recent call last):
  File "runtests.py", line 44, in <module>
    runtests()
  File "runtests.py", line 40, in runtests
    sys.exit(runner.run_tests([]))
  File "/Users/henrique/workspace/django-aggregate-if/.tox/py34-django1.7-postgres/lib/python3.4/site-packages/django/test/runner.py", line 147, in run_tests
    old_config = self.setup_databases()
  File "/Users/henrique/workspace/django-aggregate-if/.tox/py34-django1.7-postgres/lib/python3.4/site-packages/django/test/runner.py", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "/Users/henrique/workspace/django-aggregate-if/.tox/py34-django1.7-postgres/lib/python3.4/site-packages/django/test/runner.py", line 299, in setup_databases
    serialize=connection.settings_dict.get("TEST_SERIALIZE", True),
  File "/Users/henrique/workspace/django-aggregate-if/.tox/py34-django1.7-postgres/lib/python3.4/site-packages/django/db/backends/creation.py", line 374, in create_test_db
    test_flush=True,
  File "/Users/henrique/workspace/django-aggregate-if/.tox/py34-django1.7-postgres/lib/python3.4/site-packages/django/core/management/__init__.py", line 93, in call_command
    app_name = get_commands()[name]
  File "/Users/henrique/workspace/django-aggregate-if/.tox/py34-django1.7-postgres/lib/python3.4/functools.py", line 428, in wrapper
    result = user_function(*args, **kwds)
  File "/Users/henrique/workspace/django-aggregate-if/.tox/py34-django1.7-postgres/lib/python3.4/site-packages/django/core/management/__init__.py", line 73, in get_commands
    for app_config in reversed(list(apps.get_app_configs())):
  File "/Users/henrique/workspace/django-aggregate-if/.tox/py34-django1.7-postgres/lib/python3.4/site-packages/django/apps/registry.py", line 137, in get_app_configs
    self.check_apps_ready()
  File "/Users/henrique/workspace/django-aggregate-if/.tox/py34-django1.7-postgres/lib/python3.4/site-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

I need to make all tests passing before releasing 0.5. I plan to figure this out during the next week. Any help is very welcome.

kakulukia commented 9 years ago

+1 to plz fix this

trbs commented 9 years ago

https://gist.github.com/trbs/3a0d2a1756c456d5d523

Fixes:

There is still one unit test failing:

......................E...
======================================================================
ERROR: test_relabel_aliases (tests.aggregation.tests.BaseAggregateTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/private/tmp/django-aggregate-if/tests/aggregation/tests.py", line 163, in test_relabel_aliases
    b = books.get(pk=1)
  File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 351, in get
    num = len(clone)
  File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 122, in __len__
    self._fetch_all()
  File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 966, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator
    for row in compiler.results_iter():
  File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
    return Database.Cursor.execute(self, query, params)
OperationalError: no such column: aggregation_author.id

----------------------------------------------------------------------
Ran 26 tests in 1.513s

FAILED (errors=1)
Destroying test database for alias 'default'...
asteinlein commented 9 years ago

Any progress on this? Just came across this library which we would love to use, but we're on Django 1.7...

trbs commented 9 years ago

You can always install my django17 branch directly from github: https://github.com/trbs/django-aggregate-if/tree/django17

This is what I use for Django17

kakulukia commented 9 years ago

Nice to know!

trbs commented 9 years ago

Forgot that @henriquebastos committed it to git here as well... So instead of my branch people could use the github version (or specific commit) as well.

henriquebastos commented 9 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
henriquebastos commented 9 years ago

Here it is: https://twitter.com/henriquebastos/status/534844399679971329