You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When some fields have random data such as secret tokens, they will always arrive in the dumped fixture file because dbdiff relies on Django's dumpdata/loaddata code through call_command().
dbdiff has Fixture.exclude to declare fields that must be ignored from the diff test and that works. But when running with FIXTURE_REWRITE=1, new random values will always arrive in the fixture file, generating un-necessary git diffs, making it painful to commit changes.
For example (to use in dbdiff test) with this model field:
import secrets
class YourModel(models.Model):
token = models.CharField(
default=secrets.token_urlsafe,
max_length=255,
)
All tests pass ok because the env var causes full rewrites of test fixtures files with new dumps. It's now up to the developer to use something like git add -p or git checkout -p to choose which changes to add to the commit.
But the problem with random fields is that it will generate un-necessary changes such as:
To complete this issue, ensure fields in Fixture.exclude (existing feature) are not dumped at all in the dump. You can either monkey-patch the models before call_command(dumpdata) and re-add the field after, either implement your own dumpdata implementation.
The text was updated successfully, but these errors were encountered:
When some fields have random data such as secret tokens, they will always arrive in the dumped fixture file because dbdiff relies on Django's dumpdata/loaddata code through call_command().
dbdiff has Fixture.exclude to declare fields that must be ignored from the diff test and that works. But when running with FIXTURE_REWRITE=1, new random values will always arrive in the fixture file, generating un-necessary git diffs, making it painful to commit changes.
For example (to use in dbdiff test) with this model field:
Consider executing with something like:
All tests pass ok because the env var causes full rewrites of test fixtures files with new dumps. It's now up to the developer to use something like git add -p or git checkout -p to choose which changes to add to the commit.
But the problem with random fields is that it will generate un-necessary changes such as:
To complete this issue, ensure fields in Fixture.exclude (existing feature) are not dumped at all in the dump. You can either monkey-patch the models before call_command(dumpdata) and re-add the field after, either implement your own dumpdata implementation.
The text was updated successfully, but these errors were encountered: