marksweb / django-bleach

Bleach is a Python module that takes any HTML input, and returns valid, sanitised HTML that contains only an allowed subset of HTML tags, attributes and styles. django-bleach is a Django app that makes using bleach extremely easy.
MIT License
148 stars 23 forks source link

Bleach v. 5.0 is not compatible with django-bleach 1.0 #51

Closed beraneck closed 2 years ago

beraneck commented 2 years ago

Describe the bug An error is raised while saving a model with a django_bleach.models.BleachField. Our code was working until bleach released v. 5.0 yesterday (7th of April 2022).

To Reproduce Steps to reproduce the behavior:

  1. Get a fresh venv with django-bleach 1.0.0 and it's dependencies.
  2. Add a django-bleach field to a model.
  3. Save a value in the field.

Expected behavior Save don't raise the error.

Stacktrace

  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 739, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/usr/local/lib/python3.8/site-packages/model_utils/tracker.py", line 375, in inner
    return original(instance, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 776, in save_base
    updated = self._save_table(
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 881, in _save_table
    results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 919, in _do_insert
    return manager._insert(
  File "/usr/local/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 1270, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1415, in execute_sql
    for sql, params in self.as_sql():
  File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1358, in as_sql
    value_rows = [
  File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1359, in <listcomp>
    [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
  File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1359, in <listcomp>
    [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
  File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1310, in pre_save_val
    return field.pre_save(obj, add=True)
  File "/usr/local/lib/python3.8/site-packages/django_bleach/models.py", line 55, in pre_save
    clean_value = clean(data, **self.bleach_kwargs) if data else ""
TypeError: clean() got an unexpected keyword argument 'styles'

Work around Force the use of bleach 4.1.0 in your requirements.txt

django-bleach
bleach==4.1.0
marksweb commented 2 years ago

Thanks for raising @beraneck.

I'll drop a patch release preventing version 5 until this can be supported.

marksweb commented 2 years ago

@beraneck new release going out now. Turns out there was unreleased changes dropping old python/django so I've made it 2.0

beraneck commented 2 years ago

v2.0 is working perfectly, thank you for the very fast fix.

marksweb commented 2 years ago

@beraneck you're welcome. Hopefully I can find some time soon to see what bleach 5 brings and incorporate it.

Laityned commented 2 years ago

@beraneck you're welcome. Hopefully I can find some time soon to see what bleach 5 brings and incorporate it.

Made PR #55 for bleach>5 support