# Buggy code
def similar(self, unit):
    """
    Finds similar units to current unit.
    """
    ret = set([unit.checksum])
    with FULLTEXT_INDEX.source_searcher(not settings.OFFLOAD_INDEXING) as searcher:
        # Extract up to 10 terms from the source
        terms = [
            kw
            for kw, score in searcher.key_terms_from_text(
                "source", unit.source, numterms=10
            )
            if not kw in IGNORE_SIMILAR
        ]
        cnt = len(terms)
        # Try to find at least configured number of similar strings, remove up to 4 words
        while len(ret) < settings.SIMILAR_MESSAGES and cnt > 0 and len(terms) - cnt < 4:
            for search in itertools.combinations(terms, cnt):
                results = self.search(" ".join(search), True, False, False, True)
                ret = ret.union(results)
            cnt -= 1

    return self.filter(
        translation__subproject__project=unit.translation.subproject.project,
        translation__language=unit.translation.language,
        checksum__in=ret,
    ).exclude(target__in=["", unit.target])


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def similar(self, unit):
    """
    Finds similar units to current unit.
    """
    ret = set([unit.checksum])
    with FULLTEXT_INDEX.source_searcher(not appsettings.OFFLOAD_INDEXING) as searcher:
        # Extract up to 10 terms from the source
        terms = [
            kw
            for kw, score in searcher.key_terms_from_text(
                "source", unit.source, numterms=10
            )
            if not kw in IGNORE_SIMILAR
        ]
        cnt = len(terms)
        # Try to find at least configured number of similar strings, remove up to 4 words
        while (
            len(ret) < appsettings.SIMILAR_MESSAGES and cnt > 0 and len(terms) - cnt < 4
        ):
            for search in itertools.combinations(terms, cnt):
                results = self.search(" ".join(search), True, False, False, True)
                ret = ret.union(results)
            cnt -= 1

    return self.filter(
        translation__subproject__project=unit.translation.subproject.project,
        translation__language=unit.translation.language,
        checksum__in=ret,
    ).exclude(target__in=["", unit.target])