internetstandards / Internet.nl

Internet standards compliance test suite
https://internet.nl
174 stars 37 forks source link

Update django version #486

Closed gthess closed 3 years ago

gthess commented 3 years ago

Current code runs on the previous 1.11 LTS. We should at least go for 2.2 LTS or newest (3.2) by the time this issue is addressed.

baknu commented 3 years ago

https://www.djangoproject.com/download/#supported-versions

sinteur commented 3 years ago

created a WIP pull request https://github.com/NLnetLabs/Internet.nl/pull/515

baknu commented 3 years ago

JS will add details on issue he ran into regarding database threading. Would be good if GT could also check how to deal with that.

gthess commented 3 years ago

I haven't looked at it but I suppose it happens because the db object is passed to other calls. That could be easily solved by passing the id instead and querying the db again.

sinteur commented 3 years ago

The "problem" is in the file $your_local_python/dist-packages/django/db/backends/base/base.py

Specifically around line 540;


def validate_thread_sharing(self):
        """
        Validate that the connection isn't accessed by another thread than the
        one which originally created it, unless the connection was explicitly
        authorized to be shared between threads (via the `inc_thread_sharing()`
        method). Raise an exception if the validation fails.
        """
        if not (self.allow_thread_sharing or self._thread_ident == _thread.get_ident()):
            raise DatabaseError(
                "DatabaseWrapper objects created in a "
                "thread can only be used in that same thread. The object "
                "with alias '%s' was created in thread id %s and this is "
                "thread id %s."
                % (self.alias, self._thread_ident, _thread.get_ident())
            )

A bit of investigating into the history of this bit shows that it was mainly added because sqlite3 has trouble with the situation this is trying to fix. MySQL and Postgresql can safely ignore this entire issue and deal with threads just fine.

The psycopg2 postgres wrapper we're using doesn't seem to allow us to set allow_thread_sharing.

As a work-around for now I've simply added a "return" statement above the "if" in the function, but obviously we need something better.

baknu commented 3 years ago

Version 3.2 LTS: https://www.djangoproject.com/download/

baknu commented 3 years ago

https://github.com/psycopg/psycopg2/issues/1284

baknu commented 3 years ago

See also: https://github.com/internetstandards/Internet.nl/pull/585

sinteur commented 3 years ago

fixed in upcoming release 1.4