I created a simple PHP Block, and placed it in the content section. Something weird happened because the block appeared twice on the home page and once on all other pages.

I disabled the block but it remained on the home page - only the once though instead of twice.

I deleted the block. That got rid of it. However, I now get the following Notices on the home page.

•Notice: Trying to get property of non-object in block_block_view() (line 246 of /home/drupal7/public_html/modules/block/block.module).
•Notice: Trying to get property of non-object in block_block_view() (line 246 of /home/drupal7/public_html/modules/block/block.module).
•Notice: Trying to get property of non-object in ctools_block_content_type_render() (line 115 of /home/drupal7/public_html/sites/all/modules/ctools/plugins/content_types/block/block.inc).

Any ideas anybody?

Comments

trillex’s picture

Did you ever fix this and if so, how?

wackozacko’s picture

I did exactly the same thing but looking at the code in block.module figured out that the problem was occurring because there was still an entry in the database for that block. I had placed the block in the Highlighted section so ran SELECT * from block where region='highlighted to find out it's "bid" (70 in my case) and then ran DELETE from block where bid=70.Notices went away after that.

Hope that helps. I'm terrible at Drupal, but know enough about coding and databases in general to figure a few things out.

swfindlay’s picture

I have the same problem, but am unable to run the remedy suggested by wackozacko above. Can anyone suggest a simpler solution?

The error message I am getting is: "Trying to get property of non-object in block_block_view() (line 245 of ...\modules\block\block.module"

Thanks!

Clearly I'm also terrible at Drupal - but also clearly terrible at coding and databases as well!!

moneyescapade’s picture

Did you figure out a fix? I got the same problem after I deleted my block directly from the database (did this because I had faulty php code in my block which wouldnt allow me to load my page). I've searched through the database and can't find any other traces of my custom block. Help anyone?

moneyescapade’s picture

Note: I suspect this is a different problem to the original post as line 246 which may be caused by something else.

"Trying to get property of non-object in block_block_view() (line 245 of ...\modules\block\block.module"

I found a hack to solve this problem (I'm sure there is a more elegant way if someone is bothered to trace back through the block.module file and find the root of the problem). My solution is:

1. Go into your block.module file and find line 245 which should be inside a function called
function block_block_view($delta = '')
2. Add a line "print_r($delta. " ");" to this function so it becomes

function block_block_view($delta = '') {
  $block = db_query('SELECT body, format FROM {block_custom} WHERE bid = :bid', array(':bid' => $delta))->fetchObject();
  $data['subject'] = NULL;
  print_r($delta." ");
  $data['content'] = check_markup($block->body, $block->format, '', TRUE);
  return $data;
}

3. Refresh your website and you should see numbers on the top left that were not previously there, take a note of them, for me it was "7".
4. Go into your phpmyadmin area and look for the database that you deleted your block from previously (for me it was "block_custom") and go into the insert section.
5. Insert an entry with bid value equal to the value you noted in step 3; for me it was bid = 7. Do this for every single number that showed up.
6. Go back to your site, refresh it and then look into the structure -> blocks there should now be a bunch of nameless blocks created. Delete every one of them from WITHIN THE WEBSITE.
7. Go back to block.module and remove the 'print_r($delta." ");' line from earlier.

After this you should no longer get the "Notice:..." messages.

To anyone wishing to investigate the cause of this: it seems that deleting the file from the actual database is not clean and leaves traces of the entry elsewhere causing the function block_block_view to look for it.

biografica’s picture

oneyescapade got me on the right path with their method. Using the 'print_r($delta." ");' tactic, I discovered that there was a block '9' (bid in the custom_blocks table) that was being referenced on the pages the errors appeared on.

Since there was no bid=9 in the custom_blocks table, I just recreated the block through Structure > Blocks in the admin panel and manually updated the bid in the table through phpMyAdmin. That got rid of the errors.

pdolphin’s picture

Was having a similar problem and you're solution fixed it.

rwoldezghi’s picture

I can confirm this approach worked for me. I had to create dumb block in the block_custom field and then delete through admin blocks page.

haunted’s picture

That worked, thanks!

counselmancl’s picture

mysql -u root -p (enter your mysql root password)
show databases; (in case you don't know what your drupal database is called)
connect drupal; (or replace drupal with your database name)
show tables; (my error stemmed from custom_block)
select * from block_custom; (peek at what's inside. Mine was empty and causing an error)
insert into block_custom (bid) values (1); (this is assuming you already have the column bid present and the number that was returned was 1. Try it. It will probably work)

Refresh your drupal site. This should get rid of the error and create an empty block. For me, if I delete this block it will give me the error again so I just appropriated the block and all is good.

danekellyh’s picture

Thanks for the Help! Here is a little more info for anyone searching for an answer on how to fix the notice error you received after deleting a custom block in the data base because of a random piece of web php killed your site. If your using MYSQL click on your drupal database and then on block then click on SQL. Type in SELECT * from block where region='content' In my case the region was content and in wackozacko's it was highlighted. So replace content with the name of the region that you put your block in before you deleted it. This will display all the blocks in that region. Find the one that has the title you gave it and delete it. Either by clicking on the red X or by typing DELETE from block where bid= in SQL and put the number of the bid you found after the =.

k.halterman’s picture

I was able to find the erroneous blocks by "browsing" with phpmyadmin, but after deleting them the error still persists. Is there a time when the database/query forms refresh or do I have to restart the database for it to take effect?

lardi’s picture

This post help me

sascher’s picture

This worked for us, Thanks!

loopy1492’s picture

In my case, the block was deleted, but never removed from the Context module. Restoring the block and deleting it doesn't help in this case.

The block must be restored as directed above by moneyescapade, removed from the context it is being referenced in, THEN deleted.

crispin’s picture

I had deleted a custom block that was in my sitewide context, couldn't find it in the database and resaving the context still produced the error so I just deleted the offending context and created a new sitewide one - no error.

An alternative to digging around in the Database

quantos’s picture

Thanks guys. This helped me resolve the same problem too. For me it was the Context problem too and another speedy fix for this was to clone the old context (which had contained the deleted block) then delete the old context. The error immediately disappeared.

Don't shoot me. I'm just a designer.

anthonyalbertyn’s picture

Thanks for all the comments above.

This what happened in my case (D7):
I had a sitewide context that was placing three blocks in my footer region. I deleted one of the blocks from the block admin page (without removing the block from context) and got this error: Notice: Trying to get property of non-object in block_block_view() (line 245 of /modules/block/block.module).

This is what worked for me:
I went back into my sitewide context. Removed the two other blocks from the same region that the deleted block was in. Saved context. Flushed the cache. Error messages were now gone. Then added my two blocks back to my footer region in context.

treckstar’s picture

This worked great!

davethebrave’s picture

I was using a panels layout to call in the block that I had deleted. I saw that the panel region was still looking for the deleted block. So I just had to remove it from the panel and the error disappeared. So it's not just Context but the other ctools-related modules that can cause this issue/

druvision’s picture

@anthonyalbertyn, your solution worked great for me. Notice the table name is block_custom, not custom_blocks.

Prerequisites:
Verify that the orphan block exists on the blocks table and doesn't exist on the block_custom table before doing this action.

Steps:

1. Create the new block using the usuall blocks admin interface.

2. Change the bid of the newly created block to the bid of the orphan block with some SQL like
update block_custom set bid=17 where bid=22;

3. Go back to the blocks admin interface and delete the block.

augenbrauezug’s picture

Any other solutions for this? I am having the same problem except I get numbers 4 2 17 18 6 19 5 7 1 3. Most of those blocks still exist, 1 is the only deleted block. I did created block with bid 1 again in phpmyadmin and then deleted it on my site and it doesn't seem to have fixed it.

cblanglois’s picture

This is exactly what's happening to me. I have 16 numbers and only #31 is a deleted block. So I did as advised, went into phpmyadmin and added bid value = 31. (I tried to add all the other numbers but they generated errors saying they're duplicates.) Then I went to my admin block menu, and deleted the new unnamed block. It didn't fix it. The error still appears. Has someone found another solution yet? I tried to follow the other instructions below but couldn't understand them.

cblanglois’s picture

I have found a TENTATIVE solution. None of your suggestions worked for me, so I simply added back in my missing block using phpmyadmin, as suggested by moneyescapade, and kept the block in the DISABLED region. When I tried deleting it from its supposed region, the error didn't go away. Now the error is gone, but I kept the block DISABLED. Oh well, I guess that will do for now unless someone proposes another approach to the solution.

rixaman’s picture

decision:
in the table "block". at the bottom of the column "module" looking for the value of the "block".
in the next column of the "delta" value is Id custom blocks, this is the reason poblemy.

drupal tries to write data to a table that is already there.
remove the line that matches the ID your unit on your theme

p.s. sorry for the language, but I hope you can logically surmise where to dig

end user’s picture

I just got this error. What worked form was going back to blocks and setting a block into the region which held the deleted block and saved and cleared cache. That didn't fix it so I removed the block from that region, saved and clear cache. Error went away.

ericsalvi’s picture

My site showed 23 1 18 8 and I realized that 1 18 and 8 where real blocks and 23 was missing. Did exactly what you said and inserted the bid block of 23 and then removed it from my drupal admin menu. Perfect. Thanks for this one.

lcal’s picture

The solution I found for my particular setup. Maybe this will help someone else along the way.

1. Site has ctools and panels modules
2. I was cleaning up and deleted some blocks
3. Error appeared :•Notice: Trying to get property of non-object in block_block_view() (line 246 of . . .
4. Cleared cache, tried solutions above that didn't require changing a file nor the database direct, but to no avail
5. Went into panels and disabled each of them. This made the message disappear.
6. Went back to panels menu and began turning them back on. When I turned on one of them, the error returned.
7. Went to Structure >> Panels and under "Manage Pages" clicked the Edit link next to the offending panel.
8. Under "Variants" clicked Content tab.
9. Reviewed each region to find the region that had a block that no longer existed.
10. Clicked the cog icon to the right of the content box and chose "Remove."
11. Clicked "Update and Save" option and then cleared the cache for good measure.

Error was cleared.

I believe lmpreza (original poster back in 2011) likely also had panels module which is why there were two appearances of the block on the pages (the site had the content added in a panel and also in the Blocks layout). Deleting the block caused panels to serve up the error.

I hope that helps if you stumble upon this issue.

natemelen’s picture

Ical

I am having the same issue that Impreza was having and I followed your steps, but I am still getting the error message Notice: Trying to get property of non-object in block_block_view() (line 246

The block I deleted was in the disabled region of blocks, but it was still showing up on particular pages. After deleting the block the content went away, but the error message appeared. I went back in and followed your instructions (I figured out which panel was causing the problem and then found the offending panel and removed it although the title of the panel still appears. Is there a way to remove the entire panel so that the title of the panel goes away as well? Could this be causing the problem?

natemelen’s picture

I figured it out. The panel was also living somewhere else

Alan Oliveira’s picture

Run cron after delete a block also works

hassebasse’s picture

For me it was "Menu minipanles" that messed it up. On one Menu link I had added a minipanel and I had deleted one of the content panes being a part of that minipanel without relizing it actually was a part of the menu. I figured it out when I noticed that a certain Context was involved on all pages giving an error, and that Context controlled a menu. Then in one of the links I had played around when I was learning "Menu minipanels" and then simply forgot what I had been doing.

Why can't the error give an indication on what is missing? I know it was my fault, but it cost me 2 hours of work.

All the best

Hans

vinay@3347’s picture

While creating Quiz getting following error.

Trying to get property of non-object in counter_block_view() (line 157 of /drupal-7.33/modules/counter/counter.module).

  • PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'nid' cannot be null: INSERT INTO {counter} (ip,created,url, uid, nid, type, browser_name, browser_version, platform) VALUES (:ip, :created, :url, :uid, :nid, :type, :browser_name, :browser_version, :platform); Array ( [:ip] => 49.35.224.116 [:created] => 1518115689 [:url] => /node/60/take/1 [:uid] => 1 [:nid] => [:type] => [:browser_name] => Google Chrome [:browser_version] => 64.0.3282.140 [:platform] => Windows ) in counter_block_view() (line 183 of /drupal-7.33/modules/counter/counter.module).

Help would be appreciated.