Serialize lru_cache in migration files

I’m trying to use some functions with lru_cache decorator to set the on_delete option in a relation to avoid some database hits.

from functools import lru_cache

@lru_cache
def get_deleted_user():
    return User.objects.get(pk=DELETED_USER)

class Sale(models.Model):
    ...
    client = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.SET(get_deleted_user),
        related_name='sales',
    )
    ...

When I tried makemigrations Django says that can not serialize lru_cache into migration files.

I change the model and use the ‘deleted’ user pk directly and it works.

class Sale(models.Model):
    ...
        on_delete=models.SET(DELETED_USER),

I’m not sure if its the right approach but I wonder if exist a way to work with lru_cache in migration files.

as far as i know, the value you are providing in sent to the db, so it needs to be serializable so db can save it. it doesn’t makes sense to make yo use a python function for that. so i would say you approach is correct

I use a function because django recommend that and if for some reason I need to change that behavior, I only update the function logic and doesn’t generate a migration file. In this case, I don’t think that will happen so as you say I’m going to use the pk directly.
Thanks.