Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard-->vouchersets--> sorting "Num orders", "Num baskets". Cannot resolve keyword 'num_basket_additions' into field #3978

Open
martinsrudzroga opened this issue Sep 9, 2022 · 4 comments
Labels
☁ Bug Good first issue A good issue for a first time contributor to work on

Comments

@martinsrudzroga
Copy link

https://latest.oscarcommerce.com/en-gb/dashboard/vouchers/sets/?sort=num_basket_additions

@martinsrudzroga martinsrudzroga changed the title Dashboard-->vouchersets--> sorting "Num orders" Cannot resolve keyword 'num_basket_additions' into field Dashboard-->vouchersets--> sorting "Num orders", "Num baskets". Cannot resolve keyword 'num_basket_additions' into field Sep 9, 2022
@joeyjurjens joeyjurjens added ☁ Bug Good first issue A good issue for a first time contributor to work on labels Jun 23, 2023
@vallabhtiwari
Copy link
Contributor

Hi @joeyjurjens, Could you drop a hint where to look for the bug please ? I tried very much but not reaching...Thanks !!

@joeyjurjens
Copy link
Contributor

Hi @joeyjurjens, Could you drop a hint where to look for the bug please ? I tried very much but not reaching...Thanks !!

Hi, the issue occurs due to this in the template:
https://github.com/django-oscar/django-oscar/blob/master/src/oscar/templates/oscar/dashboard/vouchers/voucher_set_list.html#L39-L41

This is the Python code that belongs to it I think:
https://github.com/django-oscar/django-oscar/blob/master/src/oscar/apps/dashboard/vouchers/views.py#L315-L320

I hope that helps!

@vallabhtiwari
Copy link
Contributor

I had seen the python code(view,models,sort_queryset etc method) earlier. They all seem to be fine. Maybe I am missing something ?

@vitaliyterziev
Copy link

@vallabhtiwari you can replicate by creating an Offer, Voucher set and then try to order by in that view (see image below).

Date created will order fine since it is a database field but others (red) would not since they are computed values. Possible workarounds seems to be turning the QuerySet into list and order it or adjust the DB schema and turn those properties into fields and use post_save hook/signal to populate them. I like the first approach better although I am not that familiar with the code base and how that would impact the performance. There is another approach using extra() but it is discouraged by Django team and it is mentioned it will be deprecated at some point.

image

FieldError at /dashboard/vouchers/sets/

Cannot resolve keyword 'num_basket_additions' into field. Choices are: code_length, count, date_created, description, end_datetime, id, name, start_datetime, vouchers

Request Method:     GET
Request URL:    http://localhost:8000/dashboard/vouchers/sets/?sort=num_basket_additions
Django Version:     4.2.9
Exception Type:     FieldError
Exception Value:    

Cannot resolve keyword 'num_basket_additions' into field. Choices are: code_length, count, date_created, description, end_datetime, id, name, start_datetime, vouchers

Exception Location:     /home/vito/projects/ecommv2/.venv/lib/python3.10/site-packages/django/db/models/sql/query.py, line 1725, in names_to_path
Raised during:  oscar.apps.dashboard.vouchers.views.VoucherSetListView
Python Executable:  /home/vito/projects/ecommv2/.venv/bin/python
Python Version:     3.10.12
Python Path:    

['/home/vito/projects/ecommv2/mysite',
 '/usr/lib/python310.zip',
 '/usr/lib/python3.10',
 '/usr/lib/python3.10/lib-dynload',
 '/home/vito/projects/ecommv2/.venv/lib/python3.10/site-packages']

Server time:    Mon, 12 Feb 2024 12:54:06 +0200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☁ Bug Good first issue A good issue for a first time contributor to work on
Projects
None yet
Development

No branches or pull requests

4 participants