[Answered ]-List sent over AJAX and compared to seemingly identical list in Django returns false

2👍

I have discovered answer immediately after posting.

values_list(flat=True) does not return a list, it returns a ValuesListQuerySet.

👤lac

0👍

To add on to the OP’s own answer, The above behaviour is happening because old_message_pk_list and new_message_pk_list are of different types.

We can do a little inspection in shell.

In [1]: type(old_message_pk_list)
Out[1]: list

In [2]: type(new_message_pk_list)
Out[2]: django.db.models.query.ValuesListQuerySet

In [3]: isinstance(new_message_pk_list, list) # can see that its not a list type
Out[3]: False

In [4]: old_message_pk_list == new_message_pk_list
Out[4]: False

Though it appears that old_message_pk_list and new_message_pk_list having the same number of elements and same corresponding elements must be equal, but new_message_pk_list not being actually a list leads to False when comparing them.

Leave a comment