#13133 closed defect (fixed)
Do not add ticket change entry for default value of new ticket custom field
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.3.6 |
Component: | ticket system | Version: | |
Severity: | normal | Keywords: | custom fields |
Cc: | Branch: | ||
Release Notes: |
Ticket change entry for default value of custom field is not added to existing tickets when a new custom field is added. |
||
API Changes: | |||
Internal Changes: |
Description (last modified by )
Adding a new custom field, such as:
[ticket-custom] checkbox = checkbox checkbox.value = 0
results in a ticket change entry the next time an existing ticket is updated.
I'd like to discuss if it makes sense to skip adding the ticket_change
table entry when the ticket custom field has a default value.
Issue raised in gdiscussion:trac-users:Kind9BaSR4Q.
Attachments (1)
Change History (15)
by , 6 years ago
Attachment: | Screen Shot 2019-02-25 at 13.54.03.jpg added |
---|
comment:1 by , 6 years ago
Description: | modified (diff) |
---|
comment:2 by , 5 years ago
Milestone: | next-stable-1.2.x → 1.2.5 |
---|
comment:3 by , 5 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:4 by , 5 years ago
Milestone: | 1.2.5 → 1.3.6 |
---|
comment:5 by , 5 years ago
Release Notes: | modified (diff) |
---|
follow-up: 7 comment:6 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:7 by , 5 years ago
Replying to Ryan J Ollos:
If a time
field is updated from None
to the default value, the field is not listed in changelog.
>>> from datetime import datetime >>> from trac.util.datefmt import utc >>> from trac.test import EnvironmentStub >>> from trac.ticket.model import Ticket >>> env = EnvironmentStub() >>> env.config.set('ticket-custom', 'date1', 'time') >>> env.config.set('ticket-custom', 'date1.value', '2019-08-07T12:34:56Z') >>> env.config.set('ticket-custom', 'date1.format', 'datetime') >>> env.config.save() >>> t = Ticket(env) >>> t['summary'] = 'Summ' >>> t['status'] = 'new' >>> t['date1'] = None >>> t.insert() 1 >>> env.db_query('SELECT * FROM ticket_custom WHERE ticket=1') [(1, u'date1', None)] >>> >>> t = Ticket(env, 1) >>> t['date1'] = datetime(2019, 8, 7, 12, 34, 56, tzinfo=utc) >>> t.save_changes(comment='Set date1') # Saving with the default value for `date1` field 1 >>> env.db_query('SELECT * FROM ticket_custom WHERE ticket=1') [(1, u'date1', u'001565181296000000')] >>> list(t.get_changelog()) # `date1` field is not listed [(datetime.datetime(2019, 8, 8, 4, 42, 35, 873743, tzinfo=<FixedOffset "UTC" 0:00:00>), None, u'comment', u'1', u'Set date1', 1)]
comment:8 by , 5 years ago
Proposed change:
-
trac/ticket/model.py
diff --git a/trac/ticket/model.py b/trac/ticket/model.py index 7af629c86..170503486 100644
a b class Ticket(object): 399 399 db("""INSERT INTO ticket_custom (ticket,name,value) 400 400 VALUES(%s,%s,%s) 401 401 """, (self.id, name, db_val)) 402 # Don't add ticket change entry for custom field that403 # was added after ticket was created.404 if old_db_val is None:405 field = self.fields.by_name(name)406 default = self._custom_field_default(field)407 if self.values.get(name) == default:408 continue402 # Don't add ticket change entry for custom field that 403 # was added after ticket was created. 404 if old_db_val is None: 405 field = self.fields.by_name(name) 406 default = self._custom_field_default(field) 407 if self.values.get(name) == default: 408 continue 409 409 else: 410 410 db("UPDATE ticket SET %s=%%s WHERE id=%%s" 411 411 % name, (db_val, self.id))
I'll add test coverage.
comment:11 by , 5 years ago
CI Test failure for PostgreSQL on OSX. Should we order the changelog by field
?
-
trac/ticket/model.py
diff --git a/trac/ticket/model.py b/trac/ticket/model.py index 170503486..33b903041 100644
a b class Ticket(object): 462 462 SELECT time, author, 'comment', null, description, 463 463 0 AS permanent 464 464 FROM attachment WHERE type='ticket' AND id=%s AND time=%s 465 ORDER BY time,permanent,author 465 ORDER BY time,permanent,author,field 466 466 """ 467 467 args = (self.id, when_ts, sid, when_ts, sid, when_ts) 468 468 else: … … class Ticket(object): 477 477 SELECT time, author, 'comment', null, description, 478 478 0 AS permanent 479 479 FROM attachment WHERE type='ticket' AND id=%s 480 ORDER BY time,permanent,author 480 ORDER BY time,permanent,author,field 481 481 """ 482 482 args = (self.id, sid, sid) 483 483 log = []
follow-up: 13 comment:12 by , 5 years ago
Proposed changes in [91ede4ff0/rjollos.git], targeted to 1.0-stable. In the meantime, I've applied a fix in r17052.
comment:13 by , 5 years ago
Proposed changes in [91ede4ff0/rjollos.git], targeted to 1.0-stable. In the meantime, I've applied a fix in r17052.
The changes look good to me.
Trivial thing, Ticket.get_changelog()
is invoked twice in trunk:trac/ticket/tests/model.py.
- changelog = sorted(ticket.get_changelog()) - self.assertEqual(7, len(ticket.get_changelog())) + changelog = ticket.get_changelog() + self.assertEqual(7, len(changelog))
comment:14 by , 5 years ago
Thanks for the review. Committed to 1.0-stable in r17060, merged in r17061, r17062 (including comment:13 change).
Proposed changes in log:rjollos.git:t13133_ticket_change_custom_fields.