I suggest all error pages, messages, exceptions, etc that today use repr() be changed to use a “safe repr” function that is not overridable by the user. Something like:
The MultipleObjectsReturned error message would no longer risk triggering infinite recursion error (the exact same issue as above, but still present here).
The disadvantage is that some people will get less useful repr() if they’ve been careful to make good reprs. Unfortunately it’s quite easy to accidentally make a dangerous repr, due to the fact that Djangos default __repr__ calls __str__.
Edit:
To be really safe, this behavior could be opt-in, with a deprecation period for the non-enabled state.
This seems like the same issue are you’ve posted before… — even if it’s a variant, it’s related. It would be good to try and keep related topics all together, rather than creating small variant threads. Duplicates force people to go and find the old conversation, to remember what was said. They also risk the reasons given previously being forgotten/overlooked.
There have been other discussions in this space too. It would be worth trying to corral the considerations to see if we can resolve/improve the underlying issue.
This is exactly what I’m trying to do here. The previous attempts have all run into roadblocks (changing default repr and improving DoesNotExist), or have introduced new issues (improved MultipleObjectsReturned). I think/hope this solution would handle all these cases.
The same area sure. This specific suggestion? I don’t believe so, but maybe I missed something.
That’s kinda the point of this specific suggestion: trying to solve a wide variety of issues that have a common underlying issue, going back over a decade.
What it does is to bypass the historical discussion. What’s needed is to show how points made in the past have been accounted for.
FWIW it doesn’t do that. Using a new function admittedly doesn’t change the QuerySet/Model repr implementation, but it does change the output — which was the precise thing folks were keen to maintain.
Equally (FWIW) this does keep coming up, so maybe there is a route forward, but we can’t just pretend that the history is not there, or has been adequately accommodated when it hasn’t.
The objection that the repr would sometimes change was quite a minor point, and no one seemed to have very strong feelings about this. I also, of course, already mentioned this at the very start of this discussion.
There were several quite bad side effects of the current system mentioned. None were even acknowledged. The issue with transactions for example is quite bad in itself. This is also solved by my suggestion.
I linked to several past discussions. I don’t understand why you keep insinuating things that are clearly not true. I didn’t link to 100% of all past discussion, that’s true, but I certainly did not “pretend that the history is not there”.