openwisp / openwisp-utils

Python and Django utilities shared between different openwisp modules
https://openwisp.io/docs/dev/utils/
BSD 3-Clause "New" or "Revised" License
74 stars 72 forks source link

[fix] Fixed CopyableFieldsAdmin fields order #335 #336

Closed Aryamanz29 closed 1 year ago

Aryamanz29 commented 1 year ago

Before

Screenshot from 2023-03-23 16-56-27

After

Screenshot from 2023-03-23 16-56-40

Fixes #335

coveralls commented 1 year ago

Coverage Status

Coverage: 98.8% (+0.002%) from 98.798% when pulling 5deafdb81d0c378dad048be9801499952a0a1988 on issue-335/fix-copyable-admin-field-order into b10d3cdd1f3eadf3d224ccb5f078221b181f6721 on master.

Aryamanz29 commented 1 year ago

I found that it's the conversion of a tuple to a set or vice versa that causes the random admin field order @nemesisdesign.

Without patch

Similar post here : https://stackoverflow.com/questions/66575621/does-python-tupleset-maintains-order

    def test_copyablefields_admin_fields_order(self):
        path = reverse('admin:test_project_project_add')
        response = self.client.get(path)
        ma = ProjectAdmin(Project, self.site)
        # uuid should be missing in ma.get_fields  
        # because we're testing project admin add form
        print(ma.fields, ma.get_fields(self.client.request))
        print(ma.readonly_fields, ma.get_readonly_fields(self.client.request))   

Results:

You may have noticed that we are receiving random admin field orders, as shown below. Therefore, if you remove this patch and run the new test case that I recently added in 5deafdb (#336), it is possible that the test might pass instead of failing. This is because the set conversion behavior, which I already explained above.

Screenshot from 2023-03-24 00-17-05