-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Bug when calling a function multiple times #77
Comments
Can you give me a screenshot or the JSON that gets passed in the XHR request/responses when you are clicking the button? I've tried to replicate the best I can with the following code:
It seems to be working ok for me as shown in this gif. But, maybe with more information I can figure out what is going on. My hunch is that a component field is originally a Django model, but that for some reason the JSON data only has an integer (maybe the pk?) come across the wire. |
The model is pretty standard : class ObjA(models.Model):
name = models.CharField(max_length=42)
class ObjB(models.Model):
name = models.CharField(max_length=42)
class ObjC(models.Model):
relA = models.ForeignKey(ObjA, on_delete=models.CASCADE, related_name='objcs')
relB = models.ForeignKey(ObjB, on_delete=models.CASCADE, related_name='objcs')
value = models.FloatField() The unicorn view : class UView(UnicornView):
name = "uview"
obja = None
objc_left = None
objc_right = None
def __init__(self, *args, **kwargs):
super(self).__init__(*args, **kwargs)
self.obja = ObjA.objects.get(pk=kwargs["pk"])
def set_left(self, pk):
self.objc_left = ObjC.objects.get(pk=pk)
def set_right(self, pk):
self.objc_right = ObjC.objects.get(pk=pk) The template looks like that : <select name="left">
{% for x in obja.sub.all %}
<option value="{{ x.id }}" unicorn:click="set_left({{ x.id }})">
{% endfor %}
</select>
<select name="right">
{% for x in obja.sub.all %}
<option value="{{ x.id }}" unicorn:click="set_right({{ x.id }})">
{% endfor %}
</select> |
@nyradr Ok, I created #80 which has basically the code above so I should be able to replicate. I tweaked a few things and changed the Can you grab that branch and 1) add some code that shows the bug or 2) give me exact steps to reproduce? Thank you! |
This ended up being two different bugs. Checksums wouldn't match if the float fields ended in .0 which would get rendered as an integer in JavaScript (fixed in #82). Related models are rendered as a pk of the model, not a dictionary representation, so that needed to be handled in aaf62e8. Both fixes are published in version 0.10.1 which has been published to pypi. |
Template :
View :
When I click (at least) two times on the button, I get the error :
AttributeError: 'int' object has no attribute 'keys'
.Clicking only once the component works fine and the object is fetch. After that, any call to a component function triggers the exception.
The exception is triggered before entering the function but only when self.obj is set inside the function.
The object with the given ID exist in the database and is fetched correctly the first time the function is called.
The text was updated successfully, but these errors were encountered: