Skip to content

Fix DB docs generation

Krasimir Angelov requested to merge ka/fix/db-docs-anon-classes into master

What does this MR do and why?

Exclude classes without names (e.g. TableWithoutModel classes). Such classes result in the following error

ArgumentError: comparison of String with nil failed
/Users/krasio/projects/gitlab/gdk/gitlab/lib/tasks/gitlab/db.rake:529:in `sort'
/Users/krasio/projects/gitlab/gdk/gitlab/lib/tasks/gitlab/db.rake:529:in `block (6 levels) in <main>'
/Users/krasio/projects/gitlab/gdk/gitlab/lib/tasks/gitlab/db.rake:520:in `each'
/Users/krasio/projects/gitlab/gdk/gitlab/lib/tasks/gitlab/db.rake:520:in `block (5 levels) in <main>'
/Users/krasio/projects/gitlab/gdk/gitlab/lib/tasks/gitlab/db.rake:501:in `each'
/Users/krasio/projects/gitlab/gdk/gitlab/lib/tasks/gitlab/db.rake:501:in `block (4 levels) in <main>'
/Users/krasio/projects/gitlab/gdk/gitlab/lib/tasks/gitlab/db.rake:575:in `block (4 levels) in <main>'
/Users/krasio/.asdf/installs/ruby/3.1.4/bin/bundle:25:in `load'
/Users/krasio/.asdf/installs/ruby/3.1.4/bin/bundle:25:in `<main>'
Tasks: TOP => gitlab:db:dictionary:generate

If we debug we see this is because of an anonymous model class without #name:

   524:             file = dictionary_file_path(source_name, views, database)
   525:             key_name = "#{data_source_type(source_name, views)}_name"
   526: 
   527:             byebug if classes[source_name].any?(&:nil?)
   528:             table_metadata = {
=> 529:               key_name => source_name,
   530:               'classes' => classes[source_name]&.sort&.uniq,
   531:               'feature_categories' => [],
   532:               'description' => nil,
   533:               'introduced_by_url' => nil,
(byebug) source_name
"verification_codes"
(byebug) classes[source_name]
[nil]
(byebug)    
[#<Class:0x00000001683848c0>(created_at: datetime_with_timezone, visitor_id_code: text, code: text, phone: text)]
(byebug) model_class.descendants.select {|c| c.table_name == 'verification_codes'}.map {|c| c.name}
[nil]

Not sure why we started seeing this now, given that this class has been present for a long time, but it's good idea to exclude such classes anyway.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports