Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on Error undefined method `has_tags' or `id' for nil:NilClass during rails db:seed

Post

Error undefined method `has_tags' or `id' for nil:NilClass during rails db:seed Question

+1
−0

When running rails db:seed I get some errors without any further explanation.

CloseReason: Created 0, skipped 5
User: Created 0, skipped 1
PostFlagType: Created 0, skipped 4
PostType: Created 0, skipped 5
ReactionType: Created 0, skipped 3
SiteSetting: Created 0, skipped 57
Got error undefined method `has_tags' for nil:NilClass. Continuing...
Ability: Created 0, skipped 7
PostHistoryType: Created 0, skipped 12
Got error undefined method `id' for nil:NilClass. Continuing...
WarningTemplate: Created 0, skipped 3
TagSet: Created 0, skipped 2
License: Created 0, skipped 5

Are they critical? Should I do something?


I tried to setup QPixel again and while I could avoid another error, this one persists. I gathered more information by adding to the rescue clause of db/seeds.rb

puts "#{e.class}: #{e.message}"
puts e.backtrace.join("\n")

and got

Post
Got error undefined method `has_tags' for nil:NilClass. Continuing...
NoMethodError: undefined method `has_tags' for nil:NilClass
/home/abanta/qpixel/app/models/post.rb:52:in `block in <class:Post>'
...
/home/abanta/qpixel/db/seeds.rb:56:in `block (2 levels) in <top (required)>'
/home/abanta/qpixel/db/seeds.rb:21:in `each'
/home/abanta/qpixel/db/seeds.rb:21:in `block in <top (required)>'
/home/abanta/qpixel/db/seeds.rb:11:in `each'
/home/abanta/qpixel/db/seeds.rb:11:in `<top (required)>'

Category
Got error undefined method `id' for nil:NilClass. Continuing...
NoMethodError: undefined method `id' for nil:NilClass
(erb):4:in `block in <top (required)>'
/usr/lib/ruby/2.7.0/erb.rb:905:in `eval'
/usr/lib/ruby/2.7.0/erb.rb:905:in `result'
/home/abanta/qpixel/db/seeds.rb:16:in `block in <top (required)>'
/home/abanta/qpixel/db/seeds.rb:11:in `each'
/home/abanta/qpixel/db/seeds.rb:11:in `<top (required)>'

In the database SELECT * FROM post_types delivers

+----+-----------+-------------+-------------+-----------+----------+------------+--------------+-------------+--------------------+--------------+--------------+--------------------+-----------+----------------+---------------+-----------------------------+
| id | name      | description | has_answers | has_votes | has_tags | has_parent | has_category | has_license | is_public_editable | is_closeable | is_top_level | is_freely_editable | icon_name | answer_type_id | has_reactions | has_only_specific_reactions |
+----+-----------+-------------+-------------+-----------+----------+------------+--------------+-------------+--------------------+--------------+--------------+--------------------+-----------+----------------+---------------+-----------------------------+
|  1 | Answer    | NULL        |           0 |         1 |        0 |          1 |            1 |           1 |                  1 |            0 |            0 |                  0 | NULL      |           NULL |             1 |                           0 |
|  2 | PolicyDoc | NULL        |           0 |         0 |        0 |          0 |            0 |           0 |                  0 |            0 |            0 |                  0 | NULL      |           NULL |             0 |                           0 |
|  3 | HelpDoc   | NULL        |           0 |         0 |        0 |          0 |            0 |           0 |                  0 |            0 |            0 |                  0 | NULL      |           NULL |             0 |                           0 |
|  4 | Article   | NULL        |           0 |         1 |        1 |          0 |            1 |           1 |                  1 |            0 |            1 |                  0 | NULL      |           NULL |             0 |                           0 |
+----+-----------+-------------+-------------+-----------+----------+------------+--------------+-------------+--------------------+--------------+--------------+--------------------+-----------+----------------+---------------+-----------------------------+

Maybe that helps finding the cause and judging the severity of the issue.

I found a issue on Github from August 21 that is related to seeding, but contains only little information at the moment.

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

I'm having this issue too (1 comment)
Honestly, it sounds like there's something wrong with your setup somewhere - maybe a missed step, may... (7 comments)
Honestly, it sounds like there's something wrong with your setup somewhere - maybe a missed step, may...
ArtOfCode‭ wrote over 2 years ago

Honestly, it sounds like there's something wrong with your setup somewhere - maybe a missed step, maybe some wrong configuration - difficult to tell exactly. You shouldn't get these errors at all. Did you seed the database when you set up initially? If you look in the database now, is there anything in it?

Trilarion‭ wrote over 2 years ago

There are two databases qpixel_dev/qpixel_test. qpixel_dev has 50 tables and table post_types has 5 rows (started with four). I did seed the database (more than once).

I got the error somehow, so maybe somebody else could get the error too and then it's good if we collect information about it here. I will now do the setup again completely from scratch. Either I can reproduce the error or I cannot. I will add this to the question.

Trilarion‭ wrote over 2 years ago · edited over 2 years ago

I redid the setup again and the error persists. I debugged it a bit and added more information to the question body here. Are you sure, that this should not happen? I think I may be able to describe a procedure to reproduce it. Seeding isn't really covered by tests and circleci, or is it?

Trilarion‭ wrote over 2 years ago

I also updated https://collab.codidact.org/posts/285516 with new information. It looks slightly different than before but still something is strange there. Probably related to this one here.

Trilarion‭ wrote over 2 years ago

Next thing I will try is doing rails db:seed on the commit that CD is running on currently from 2021-11-27. Maybe it works there.

Trilarion‭ wrote over 2 years ago

I went back to the revision of 2021-11-27 but nothing changed. Maybe I should investigate more what these errors mean. I guess a post type needs to "has_tags" in order to be used as something that one can post, but it seems that in db/seeds/post_types.yml there are five default post types defined and somehow I don't get "Question" seeded in the database for some reason.

sau226‭ wrote about 2 years ago

The has_tags issue can be fixed by visiting http://your_dev_site/categories and adding a Q&A/Meta category, selecting a tag set from (posting) >> tag set >> "Main" (for Q&A) or "Meta" (for Meta).

I'm not sure about the ID one though.