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

Error modifying/updating child components in 0.18.0 #141

Closed
cleonello opened this issue Feb 1, 2021 · 3 comments
Closed

Error modifying/updating child components in 0.18.0 #141

cleonello opened this issue Feb 1, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@cleonello
Copy link

I have encountered an error when updating child components in 0.18.0 that was not present in 0.17.2. I have a parent table with child rows created like so:

<tbody class="text-gray-500">
    {% for payment in payments_display %}
        {% unicorn 'payment_row' parent=view payment=payment key=payment.id %}
    {% endfor %}
</tbody>

Each child row has a checkbox for the user to select the row for further processing:

<tr class="{% if disabled %} text-gray-400 {% endif %}">
    <td class="px-2 py-3 align-top">
        <input u:click="toggle_check" type="checkbox" id="payment_{{ payment.id }}" {% if selected %} checked {% endif %} {% if disabled %} disabled {% endif %}/>
        <label for="payment_{{ payment.id }}"> {{ payment.id }}</label>
    </td>
    <td class="px-2 py-3 align-top">{{ payment.payment_date }}</td>
    ...
</tr>

When the checkbox is checked/unchecked, the child row add/removes itself from the list of selected rows on the parent, as defined in the component's toggle_check method:

class PaymentRowView(UnicornView):
    payment = None
    selected = False
    disabled = False

    def mount(self):
        if self.payment['ucrmqb_posted'] == True:
            self.disabled = True

    def toggle_check(self):
        self.selected = not self.selected

        try:
            idx = int(self.payment['id'])
        except:
            print('Error converting index')
            return

        selids = self.parent.selected_payment_ids
        selpays = self.parent.selected_payments


        if selids.count(idx):
            sidx = selfids.index(idx)
            selids.pop(sidx)
            selpays.pop(sidx)

        else:
            selids.append(idx)
            selpays.append(self.payment)

Toggling the checkbox worked fine and as expected in 0.17.2 and prior versions. In version 0.18.0, I get the following error when clicking the checkbox:

Internal Server Error: /unicorn/message/payment_row
Traceback (most recent call last):
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django_unicorn/decorators.py", line 59, in timed
    result = wrapped(*args, **kwargs)
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django_unicorn/views.py", line 32, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django/views/decorators/http.py", line 40, in inner
    return func(request, *args, **kwargs)
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django_unicorn/views.py", line 719, in message
    json_result = _handle_component_request(request, component_request)
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django_unicorn/views.py", line 576, in _handle_component_request
    return _process_component_request(request, component_request)
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django_unicorn/views.py", line 278, in _process_component_request
    component = UnicornView.create(
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django_unicorn/decorators.py", line 59, in timed
    result = wrapped(*args, **kwargs)
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django_unicorn/components.py", line 795, in create
    component = _construct_component(
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django_unicorn/decorators.py", line 59, in timed
    result = wrapped(*args, **kwargs)
  File "/Users/chris/miniconda3/envs/uqb/lib/python3.9/site-packages/django_unicorn/components.py", line 787, in _construct_component
    component.mount()
  File "/Users/chris/proj/uqbproj/unicorn/components/payment_row.py", line 13, in mount
    if self.payment['ucrmqb_posted'] == True:
TypeError: 'NoneType' object is not subscriptable
[01/Feb/2021 02:03:44] "POST /unicorn/message/payment_row HTTP/1.1" 500 16651

Is this a bug or do I have something incorrect?

@adamghill
Copy link
Owner

Sorry about this regression. This is a bug and it's related to kwargs being passed into a component (similar to #140). I've been trying to figure out a decent solution for most of today, but for now I would suggest to stay on 0.17.2. I am close to having a solution, but I would like to do more testing before releasing it so I don't create more problems. Sorry again for the issue -- I will update this issue when I release a fix (hopefully within the next day).

@adamghill adamghill self-assigned this Feb 1, 2021
@adamghill adamghill added the bug Something isn't working label Feb 1, 2021
@cleonello
Copy link
Author

Will do. I reverted back to 0.17.2. No problem for me to continue using that version for the time being. I appreciate your quick response!

@adamghill
Copy link
Owner

I just released 0.18.1 which should allow a component's parent to be set correctly again. Closing for now, but let me know if you run into other issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants