Skip to content
This repository has been archived by the owner on Mar 29, 2019. It is now read-only.

Re-implement sorting in API responses #51

Open
mileswwatkins opened this issue May 1, 2015 · 3 comments
Open

Re-implement sorting in API responses #51

mileswwatkins opened this issue May 1, 2015 · 3 comments

Comments

@mileswwatkins
Copy link
Contributor

As of now, it's impossible to sort search endpoints by created_at and similar datetimes. This may have something to do with #49.

@mileswwatkins
Copy link
Contributor Author

I've set the docs to have no sort abilities for now; this should be fixed accordingly once Imago has it fixed.

@fgregg
Copy link
Contributor

fgregg commented Dec 15, 2015

It doesn't seem to be possible to sort by anything:

http://ocd.datamade.us/bills/?from_organization=ocd-organization/ef168607-9135-4177-ad8e-c1f7a4806c3a&sort=identifier

yields

ProgrammingError: SELECT DISTINCT ON expressions must match initial ORDER BY expressions
LINE 1: SELECT COUNT(*) FROM (SELECT DISTINCT ON ("opencivicdata_bil...
                                                  ^

  File "django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "django/utils/decorators.py", line 67, in _wrapper
    return bound_func(*args, **kwargs)
  File "django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "django/utils/decorators.py", line 63, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "restless/views.py", line 106, in dispatch
    response = super(Endpoint, self).dispatch(request, *args, **kwargs)
  File "django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "imago/helpers.py", line 137, in _
    return fn(self, request, *args, **kwargs)
  File "imago/helpers.py", line 122, in _
    return fn(self, request, *args, **kwargs)
  File "imago/helpers.py", line 307, in get
    data_page = self.paginate(data, page, per_page)
  File "imago/helpers.py", line 266, in paginate
    return paginator.page(page)
  File "django/core/paginator.py", line 50, in page
    number = self.validate_number(number)
  File "django/core/paginator.py", line 39, in validate_number
    if number > self.num_pages:
  File "django/core/paginator.py", line 86, in _get_num_pages
    if self.count == 0 and not self.allow_empty_first_page:
  File "django/core/paginator.py", line 72, in _get_count
    self._count = self.object_list.count()
  File "django/db/models/query.py", line 371, in count
    return self.query.get_count(using=self.db)
  File "django/db/models/sql/query.py", line 483, in get_count
    number = obj.get_aggregation(using, ['__count'])['__count']
  File "django/db/models/sql/query.py", line 464, in get_aggregation
    result = compiler.execute_sql(SINGLE)
  File "django/db/models/sql/compiler.py", line 852, in execute_sql
    cursor.execute(sql, params)
  File "django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)

Is this the same or a different issue @mileswwatkins

@mileswwatkins
Copy link
Contributor Author

Hmm, I'm not sure, but I would suspect so. Regardless, fixing one will almost surely fix the other.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants