From 0ee750cb515c674a36b1560f0ee76dde182ac032 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 24 2021 08:25:19 +0000 Subject: [PATCH 1/2] get_tag and accepts "auto" event If "auto" is passed as an event value, latest record will be returned without checking "active" status. "revoke_event" will be then added to returned taginfo. If it is None, then it is active record, otherwise it will contain event id. Fixes: https://pagure.io/koji/issue/1506 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 0f13686..d2e4f04 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -3299,6 +3299,9 @@ def get_tag(tagInfo, strict=False, event=None, blocked=False): Note that in order for a tag to 'exist', it must have an active entry in tag_config. A tag whose name appears in the tag table but has no active tag_config entry is considered deleted. + + event option can be either event_id or "auto" which will pick last + recorded create_event (option for getting deleted tags) """ tables = ['tag_config'] @@ -3311,17 +3314,27 @@ def get_tag(tagInfo, strict=False, event=None, blocked=False): 'tag_config.arches': 'arches', 'tag_config.locked': 'locked', 'tag_config.maven_support': 'maven_support', - 'tag_config.maven_include_all': 'maven_include_all' + 'tag_config.maven_include_all': 'maven_include_all', } - clauses = [eventCondition(event, table='tag_config')] + data = {'tagInfo': tagInfo} + + clauses = [] if isinstance(tagInfo, int): clauses.append("tag.id = %(tagInfo)i") elif isinstance(tagInfo, str): clauses.append("tag.name = %(tagInfo)s") else: raise koji.GenericError('Invalid type for tagInfo: %s' % type(tagInfo)) + if event == "auto": + # find active event or latest create_event + opts = {'order': '-create_event', 'limit': 1} + query = QueryProcessor(tables=['tag_config'], columns=['create_event'], + joins=['tag on tag.id = tag_config.tag_id'], + clauses=clauses, values=data, opts=opts) + event = query.executeOne()['create_event'] + fields['tag_config.revoke_event'] = 'revoke_event' + clauses.append(eventCondition(event, table='tag_config')) - data = {'tagInfo': tagInfo} fields, aliases = zip(*fields.items()) query = QueryProcessor(columns=fields, aliases=aliases, tables=tables, joins=joins, clauses=clauses, values=data) From 7916b522325465abd01ca9e50b04246bc06ae2c9 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 28 2021 09:08:42 +0000 Subject: [PATCH 2/2] updates --- diff --git a/hub/kojihub.py b/hub/kojihub.py index d2e4f04..148bbbb 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -3328,11 +3328,21 @@ def get_tag(tagInfo, strict=False, event=None, blocked=False): if event == "auto": # find active event or latest create_event opts = {'order': '-create_event', 'limit': 1} - query = QueryProcessor(tables=['tag_config'], columns=['create_event'], + query = QueryProcessor(tables=['tag_config'], columns=['create_event', 'revoke_event'], joins=['tag on tag.id = tag_config.tag_id'], clauses=clauses, values=data, opts=opts) - event = query.executeOne()['create_event'] - fields['tag_config.revoke_event'] = 'revoke_event' + try: + event = query.executeOne(strict=True)['revoke_event'] + except koji.GenericError: + event = None + if event is not None: + # query point instantly before the revoke_event + # (to get latest tag_config before deletion) + event -= 1 + fields['tag_config.revoke_event'] = 'revoke_event' + else: + # if tag is not deleted, query event=None + pass clauses.append(eventCondition(event, table='tag_config')) fields, aliases = zip(*fields.items())