-
Notifications
You must be signed in to change notification settings - Fork 897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Classification parent #18301
Classification parent #18301
Conversation
@kbrock There's a lot going on here, but I can't tell if this is all drive-by cleanups or required to get parent_id => nil working. Also as I mentioned in the migration PR, I'd prefer we just cut off parent_id 0 altogether, with the migration of 0 to nil being the cutover point. |
12bfba1
to
2d8e92c
Compare
Re: Rubocop The rubocop comments don't make sense for this PR. The |
WIP: splitting this up |
I did see your WIP message but finally found some time so reviewed first commit ("Tag#find_by_classification_name"). LGTM on that, with couple of optional suggestions. [The root cause of many things that annoy me around namespaces is that Classification pretends it knows its namespace but actually gets it from slicing the name of the associated tag (unless it's a new classification that first knows its ns, then uses that to compute |
2d8e92c
to
ba2ea1f
Compare
app/models/classification.rb
Outdated
@@ -395,7 +398,7 @@ def self.import_from_hash(classification, parent = nil) | |||
|
|||
stats = {"categories" => 0, "entries" => 0} | |||
|
|||
if classification["parent_id"] == 0 # category | |||
if parent.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the hash contains (or might contain?) a "parent_id"
key, and we get a parent
arg as well?
Checking parent
looks fine, but are the two always in sync? Below (L411) we create(classification)
which would use classification["parent_id"]
, ignoring parent
.
Looking at db/fixtures/classifications.yml, categories come with :parent_id: 0
, and entries without :parent_id
.
OK, I think I see. The recursive call goes into the other branch, which sets "parent_id" => parent.id
.
=> Assuming the imported yaml is always rooted at categories, LGTM.
Consider also forcing "parent_id" => parent.id in the categories branch too.
P.S. db/fixtures/classifications.yml is not really relevant. That file is loaded by .seed
which uses completely separate code 🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import_from_yaml->import_from_hash code path is only used by tools/import_tags.rb
. I don't think we have tests or examples what input looks like, although it's pretty obvious it should be symmetric to tools/export_tags.rb
-> Classification.export_to_yaml
. That one is always rooted at categories, omitting "parent_id"
from entries => satisfies assumptions here 👍
There is also a 3rd completely separate importing code in lib/task_helpers/imports/tags.rb
.
And a 4th completely separate https://github.com/rhtconsulting/cfme-rhconsulting-scripts/blob/master/rhconsulting_tags.rake
😕 🤦♂️ 😆
oh well, consolidating is totally not the goal here, I'm just amused.
EDIT: 3rd was based on 4th (#16983)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- However you also need to update lib/task_helpers/exports/tags.rb, which has
:parent_id => 0
. - lib/task_helpers/imports/tags.rb looks unaffected to me?
Tag.in_region(region_id).find_by(:name => tag_name) | ||
end | ||
|
||
def save_tag | ||
tag_name = Classification.name2tag(name, parent_id, ns) | ||
tag_name = Classification.name2tag(name, parent, ns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orthogonal to this PR but valid optimization, avoids unnecessary find
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this was unnecessary
(but I can't bring myself to remove it :) )
1de6131
to
524f7b4
Compare
524f7b4
to
1ad70ac
Compare
Looks great! 💯 Didn't look deep into Travis failures. Must be tested locally with schema change. if category?
@ns = tag2ns(tag.name)
else
@ns = tag2ns(parent.tag.name) unless parent_id.nil?
end Huh. So there are presently situations when parent_id is nil, which is distinct from parent_id==0 meaning a category?! 😕 |
Yea, think that is present when creating records. Merging re: travis failures From what I can tell, I think this is failing travis because the database itself has a But this assumption is also why I want to get as much code out of here. |
1ad70ac
to
07800d4
Compare
07800d4
to
dd5238d
Compare
db65f63
to
88d5077
Compare
[I've gone silent partly because I hoped to look deeper into "present situations when parent_id is nil" but never found the time, but also because I wasn't sure if this is finished. Please ping me explicitly if you want another look.] |
88d5077
to
21aec89
Compare
21aec89
to
7c5f3d1
Compare
Checked commit kbrock@7c5f3d1 with ruby 2.3.3, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 app/models/classification.rb
|
blocked:
Extracted from #17210
Thanks for pinging me on this one @Fryguy
Before:
Currently we use
Classification#parent_id == 0
to mean there is aCategory
and it has noparent
.After
ActiveRecord
has the convention of havingparent_id == nil
to mean there is noparent
.So we follow that convention:
Classification#parent_id == nil
when this is aCategory
and it has noparent
.We now pass around
nil
when there is no parent (we were passing0
). But we still handle passing a0
in case some code is not properly updated across the various repos.This PR:
name2tag
.Tag.find_by_classification_name
.parent_id
value, using more scopes.parent_id
of0
ornil
.