-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Description
settings
INSTALLED_APPS = [
...
"pgcrypto",
...
]
...
# DB column encryption
ENCRYPTION_KEY=config("DB_ENC_KEY")
# Used by TextHMACField and PGPSymmetricKeyField if not specified by the db
PGCRYPTO_KEY=ENCRYPTION_KEY
...
model
class Region(models.Model):
...
env_enc = TextPGPSymmetricKeyField(blank=True, null=True)
...
shell
>>> from hunts.models import *
>>> region = Region(name='test', aws_region='us-east-1', env_enc="KEY=value\nKEY2=value", api_url="https://api.example.com")
>>> region.save()
>>> r = Region.objects.all().first()
>>> r.__dict__
{'_state': <django.db.models.base.ModelState object at 0x7fd0e9769390>, 'id': 1, 'name': 'test', 'aws_region': 'us-east-1', 'active': True, 'notes': None, 'env': None, 'env_enc': None, 'api_url': 'https://api.example.com', 'created_time': datetime.datetime(2025, 5, 20, 10, 50, 41, 432802, tzinfo=datetime.timezone.utc), 'updated_time': datetime.datetime(2025, 5, 20, 10, 50, 41, 432819, tzinfo=datetime.timezone.utc)}
>>> r.env_enc
>>>
As you can see, the env_enc shows as None in the __dict__ output. But I know the data is in the DB from a raw SQL query:
db=> select * from region where id = 3;
id | name | aws_region | active | notes | env | api_url | created_time | updated_time |
env_enc
----+------+------------+--------+-------+-----+-------------------------+-------------------------------+-------------------------------+---------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------
3 | test | us-east-1 | t | | | https://api.example.com | 2025-05-20 11:25:32.099441+00 | 2025-05-20 11:25:32.099458+00 | \xc30d04070302438a5e
0f8ed02f636ad245015ffd201e4c8a26100df72f5340a72b9c698378445a485017b35fab0a4f96fccfc1a59cc8a0e14a9d233b7317106ec562c9fbb1b1b5353c1a6443414b5a02e02a600a8fbe
(1 row)
Any help or tips would be greatly appreciated!
Metadata
Metadata
Assignees
Labels
No labels