morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
211 stars 64 forks source link

m2m_foreign_field TypeError when foreign field is null in database #40

Closed dcornu closed 2 years ago

dcornu commented 3 years ago

https://github.com/morlandi/django-ajax-datatable/blob/10229938371f439f8dab7981d1555c4325f4942b/ajax_datatable/columns.py#L227

Hi,

Congrats for this project, it is very useful and easy to get results even when we do not know how it works deeply. I'm just starting using your module but I think I found a bug. So forgive me if I'm mistaking.

I want to display a ManyToMany field value which is not always available in the database (the field can be NULL). When the DB field is NULL, the code crashes at line 227 with the following error :

File "/usr/local/lib/python3.9/site-packages/ajax_datatable/columns.py", line 227, in get_foreign_value
    current_value = ', '.join(list_values)
TypeError: sequence item 0: expected str instance, NoneType found

It would be interesting to check if list_values is None and put blank or a default value if it is None.

Thank you

morlandi commented 3 years ago

m2m_foreign_field is a recent contribution of @etiennepouliot ... let's hear his opinion on this.

See: https://github.com/morlandi/django-ajax-datatable/pull/36#issuecomment-917373629

etiennepouliot commented 3 years ago

Yes, I will fix this.

morlandi commented 2 years ago

Fix with PR #57 and merged into master. I will publish a new version for Pypi soon, after marging PR #65 too