Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken for models with non-numeric primary key #28

Open
regiohelden-dev opened this issue Aug 26, 2020 · 3 comments
Open

Broken for models with non-numeric primary key #28

regiohelden-dev opened this issue Aug 26, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@regiohelden-dev
Copy link

  • Django Scrubber version: any
  • Django version: any
  • Python version: any
  • Operating System: any

Description

Model with non-numeric primary key will fail because of mod annotations.
model.objects.annotate( mod_pk=F('pk') % settings_with_fallback('SCRUBBER_ENTRIES_PER_PROVIDER') ).update(**realized_scrubbers)

What I Did

class Token(models.Model):
    key = models.CharField(_("Key"), max_length=40, primary_key=True)
    user = models.OneToOneField(
        settings.AUTH_USER_MODEL, related_name='external_auth_token',
        on_delete=models.CASCADE, verbose_name=_("User")
    )
    created = models.DateTimeField(_("Created"), auto_now_add=True)

    class Scrubbers:
        key = scrubbers.Concat(scrubbers.Hash('key'), scrubbers.Faker('pystr', min_chars=5, max_chars=15))

Running scrub_data will fail with this log:

psycopg2.errors.UndefinedFunction: operator does not exist: character varying % integer
django.db.utils.ProgrammingError: operator does not exist: character varying % integer
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

@mounirmesselmeni mounirmesselmeni added the bug Something isn't working label Aug 26, 2020
@mounirmesselmeni
Copy link
Contributor

@costela Any thoughts about this one?

@costela
Copy link
Collaborator

costela commented Aug 26, 2020

@mounirmesselmeni This is a bit tricky, because we need some way to consistently map faked content to the scrubbed model's rows. The current "naive" way of doing pk % len(fakes) is pretty fast and easy, but only works for numbers.

Maybe we could add some option to convert the key to an int with something like ABS(('x'||MD5(XXX))::BIT(64)::BIGINT) (where XXX is the field name). This probably has a performance impact and should therefore be optional.

@mounirmesselmeni
Copy link
Contributor

mounirmesselmeni commented Aug 26, 2020

Yeah we can inspect the type of the field and do it only for Charfield

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants