﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35648	SafeString and overriding addition do not work well together	Matthias Kestenholz	Matthias Kestenholz	"When you have an object which is added to a string you can override `__radd__`.

However, the current implementation of `SafeString.__add__` unconditionally calls `super().__add__`, which means that the RHS doesn't get a chance at handling the addition. I propose making `SafeString.__add__` a bit more defensive and only call `super().__add__` if it actually knows that it can handle the type.

The full diff of my proposed change is here:
https://github.com/django/django/compare/main...matthiask:django:safe-string-add-safety

The first commit is https://github.com/django/django/commit/2a118c2bec3e2952b7ab344e12e95cf42554cd5b

It shows that overriding `__radd__` works with `str` objects on the LHS but doesn't work with `SafeString` objects.

The second commit is https://github.com/django/django/commit/61767c66c00323b7b862d812679879a4fdc47a43

It allows the test to pass. I'm not 100% sure the proposed `__add__` implementation handles everything it should.

"	Bug	closed	Utilities	dev	Normal	fixed	safestring		Ready for checkin	1	0	0	0	0	0
