Closed othalan closed 2 years ago
Here is test code for this bug and to verify the fix:
import justpy as jp
class TestAgGrid(jp.AgGrid):
_test_prop_value = 1
@property
def test_prop_double(self):
return self._test_prop_value
@test_prop_double.setter
def test_prop_double(self, value):
# Double the input value so that this is a non-trivial test case
print(f'setting test property: {value} * 2 => {value * 2}')
self._test_prop_value = value * 2
wp = jp.WebPage()
grid = TestAgGrid(a=wp)
assert grid.test_prop_double == 1 # Verify initial condition
# Set a new value to the property
grid.test_prop_double = 2
# Verify the property was set
if grid.test_prop_double == 1:
print('BUG: Test property not set')
elif grid.test_prop_double == 4:
print('FIXED: Test Property set as expected!')
else:
print('Unknown BUG in test code')
Thanks! This was a bug also in HighCharts. I fixed both.
The current implementation of
AgGrid.__setattr__
breaks class properties (@property
) because it bypasses normal setattr functionality built into python. Class properties cannot be set.The following diff shows how to fix the bug:
A more robust implementation (also the python recommended implementation) would be to turn
AgGrid.options
into a class property, eliminating the need for setattr and improving the quality of the code. The change simplifies the code and looks like this:I personally recommend the second fix (moving
options
into a class property) as it improves the overall code quality, however both versions of the above code fix this bug adequately.Both diffs above are against the latest code base, v0.1.5. Let me know if you want a pull request.