#3123 Centralize name/id lookup clauses
Merged by tkopecek. Opened by mikem.
mikem/koji name-or-id-clause  into  master

Download 3123.patch

This is a much more significant riff on PR #3118.

This change centralizes logic for accepting either name or id (or a dict containing such) for a value lookup.
The logic is handled in a new name_or_id_clause() function, which is called several places to generate an appropriate query clause for the value to look up.
In the process, several functions were updated to avoid raw sql queries and numerous unit tests were added or updated.

Fixes https://pagure.io/koji/issue/3122

There are a few places that do name or id lookup that I have not ported to use this new function:

  • get_user includes some special cases and already handles a dict parameter
  • readPackageList, readTaggedBuilds, readTaggedRPMS, and readTaggedArchives are all very complex queries with many parameters. We might want to use this function there as well (possibly for multiple parameters), but I've left them alone for now since this is more work and none of these are simple lookup calls.

the table should be 'build_target'

It seems an error is needed in some cases, if neither 'id' nor 'name' in the dict. Maybe a strict option makes more sense?

1 new commit added

  • fix table name

the table should be 'build_target'

Thanks! Good catch!

It seems an error is needed in some cases, if neither 'id' nor 'name' in the dict. Maybe a strict option makes more sense?

Sure, it would error anyway in the next stanza, since info will be neither an int or str. Still, explicit is better than implicit. I'll add the error case to be clearer.

I don't think a strict option makes sense here. If we can't return a clause, we have to error.

1 new commit added

  • add explicit error case

:thumbsup:

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

Metadata Update from @jcupova:
- Pull-request untagged with: testing-ready

Dropped testing-ready, because:
./koji add-host-to-channel kojibuilder test-channel-2 --new

returns:
koji: Fault: : 'NoneType' object is not subscriptable">

@mikem can you fix it, please?

Ah, good catch. It's a silly typo. Will fix momentarily

1 new commit added

  • actually execute the insert

works for me with the update

$ lkoji add-host-to-channel builder-05 test-channel-8 --new
$ lkoji list-hosts --channel test-channel-8
Hostname   Enb Rdy Load/Cap  Arches           Last Update                         
builder-05 Y   N    0.0/2.0  x86_64,i686      -              

Metadata Update from @mikem:
- Pull-request tagged with: testing-ready

Thanks @mikem for quick fix. Working, QE will continue on checking more.

Commit a131f838 fixes this pull-request

Pull-Request has been merged by tkopecek

Metadata Update from @jobrauer:
- Pull-request tagged with: testing-done

Metadata