line / promgen

Promgen is a configuration file generator for Prometheus
https://line.github.io/promgen/
MIT License
1.04k stars 150 forks source link

Fix testing Rule query before saving #510

Closed vincent-olivert-riera closed 1 month ago

vincent-olivert-riera commented 1 month ago

When creating a new Rule and testing its query before saving it, an error like this was happening:

'Rule' instance needs to have a primary key value before this relationship can
be used.

From the user's perspective, the test was not happening and the server returned a 500 error.

When testing a new Rule that has not been saved, a temporary Rule object is created in memory. Since that object is not saved, it does not contain a primary key.

Due to some changes introduced in Django 4, errors are thrown if that object without a primary key is used. To fix that issue, we manually assign a primary key.