Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
beraneck opened this issue Apr 8, 2022 · 5 comments
Closed

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

beraneck opened this issue Apr 8, 2022 · 5 comments

Comments

@beraneck
Copy link

beraneck commented Apr 8, 2022

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
Copy link
Owner

marksweb commented Apr 8, 2022

Thanks for raising @beraneck.

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

@marksweb
Copy link
Owner

marksweb commented Apr 8, 2022

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

@beraneck
Copy link
Author

beraneck commented Apr 8, 2022

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

@marksweb
Copy link
Owner

marksweb commented Apr 8, 2022

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

facundobatista pushed a commit to PyAr/pyarweb that referenced this issue Apr 20, 2022
* Added pytest as a runner

* Added pytest as a runner on Makefile

* Added joboffers app

* Some fixes to the JobOffer model

* Added initial joboffer detail

* Added initial job offer add form

* Changed joboffer's urls to use their namespace

* Added some basic pytest's fixtures

* Updated JobOffer's factory to include all the needed fields

* Added joboffer creation test

* Added joboffer admin page

* Moved add button to bottom of the page (joboffers)

* Added search button in admin page (joboffers)

* Added joboffer edit view

* Changed joboffer's choices to their long version

* Added skeleton for joboffer publisher and test

* Added publisher test

* Added facebook publsiher WIP

* Added support for posting to facebook WIP

* Refactor publisher locations

* Continue refactor of publishers

* Added test for rendering tempaltes for a publisher.

* Change Docstring for publisher.

* Added error handling to facebook publisher.

* Added test for publisher methods

* Put publish method for publishers in base class

* Fix typo

* Added test for raw publishing of facebook messages.

* Added new test to facebook publish method.

* Fix linter issues

* Added documentation for running the token creator

* Fix linting error

* Working Tweet updating example

* Add skeleton of twitter publisher

* More files added to twitter publisher

* Fixed some wording and redundat variable declaration

* Change Publisher class methods into normal methods and put publish inside the class.

* Change log formatting

* Removed misleading server error

* Fixed linting issues

* Working Tweet updating example

* Add skeleton of twitter publisher

* More files added to twitter publisher

* Added BaseCommand for testing publishers.

* Added twitter publisher tests

* Added twitter publisher test for happy path

* Change string representation for logging

* Splited telegram notifier into an api and a notifier, so it can be reused in the telegram publisher

* Added telegram publisher

* Added new variable to public chat id

* Added logging for telegram errors.

* Fix extra quotes on error constants

* Splited telegram notifier into an api and a notifier, so it can be reused in the telegram publisher

* Added telegram publisher

* Added new variable to public chat id

* Added logging for telegram errors.

* Removed redundant return value assignment

* Added title to publisher

* Adeded hash_secret method

* Now logging secrets as hashes

* Hashing credentials for telegram.

* Fixed wording in log

* Change lenght of body for testing message of publishers

* Added environment variables for discourse

* Added tests for discourse

* Pin Bleach to an older version until this issue [0] gets fixed.

marksweb/django-bleach#51

* Fix formatting issues

* Added uuid to post titles

* Added comment for pinning bleach

Co-authored-by: German Podesta <german.m.podesta@gmail.com>
Co-authored-by: Germán <german_podesta@yahoo.com.ar>
Co-authored-by: Ian Puchetti <ianpuchetti@gmail.com>
@Laityned
Copy link
Contributor

@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

pyguru-dev added a commit to pyguru-dev/python-ar-web that referenced this issue Sep 29, 2023
* Added pytest as a runner

* Added pytest as a runner on Makefile

* Added joboffers app

* Some fixes to the JobOffer model

* Added initial joboffer detail

* Added initial job offer add form

* Changed joboffer's urls to use their namespace

* Added some basic pytest's fixtures

* Updated JobOffer's factory to include all the needed fields

* Added joboffer creation test

* Added joboffer admin page

* Moved add button to bottom of the page (joboffers)

* Added search button in admin page (joboffers)

* Added joboffer edit view

* Changed joboffer's choices to their long version

* Added skeleton for joboffer publisher and test

* Added publisher test

* Added facebook publsiher WIP

* Added support for posting to facebook WIP

* Refactor publisher locations

* Continue refactor of publishers

* Added test for rendering tempaltes for a publisher.

* Change Docstring for publisher.

* Added error handling to facebook publisher.

* Added test for publisher methods

* Put publish method for publishers in base class

* Fix typo

* Added test for raw publishing of facebook messages.

* Added new test to facebook publish method.

* Fix linter issues

* Added documentation for running the token creator

* Fix linting error

* Working Tweet updating example

* Add skeleton of twitter publisher

* More files added to twitter publisher

* Fixed some wording and redundat variable declaration

* Change Publisher class methods into normal methods and put publish inside the class.

* Change log formatting

* Removed misleading server error

* Fixed linting issues

* Working Tweet updating example

* Add skeleton of twitter publisher

* More files added to twitter publisher

* Added BaseCommand for testing publishers.

* Added twitter publisher tests

* Added twitter publisher test for happy path

* Change string representation for logging

* Splited telegram notifier into an api and a notifier, so it can be reused in the telegram publisher

* Added telegram publisher

* Added new variable to public chat id

* Added logging for telegram errors.

* Fix extra quotes on error constants

* Splited telegram notifier into an api and a notifier, so it can be reused in the telegram publisher

* Added telegram publisher

* Added new variable to public chat id

* Added logging for telegram errors.

* Removed redundant return value assignment

* Added title to publisher

* Adeded hash_secret method

* Now logging secrets as hashes

* Hashing credentials for telegram.

* Fixed wording in log

* Change lenght of body for testing message of publishers

* Added environment variables for discourse

* Added tests for discourse

* Pin Bleach to an older version until this issue [0] gets fixed.

marksweb/django-bleach#51

* Fix formatting issues

* Added uuid to post titles

* Added comment for pinning bleach

Co-authored-by: German Podesta <german.m.podesta@gmail.com>
Co-authored-by: Germán <german_podesta@yahoo.com.ar>
Co-authored-by: Ian Puchetti <ianpuchetti@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants