After calling node_type_save(), _node_types_build() doesn't bother to unset 'is_new', which creates bugs futher down the line. The new type is in the database, but node_type_get_types() says it isn't by virtue of is_new=1.

There is also currently a problem with static caching in _node_types_build() -- $_node_types is only linked with drupal_static() if (!$rebuild), meaning that during a rebuild, the static cache is not touched. Subsequent calls to node_type_get_types() may fall back on stale static data, and actions performed on $_node_types during node_types_rebuild() may not be active until a new page load.

This bug is blocking #890128: Comment body missing if comment module enabled after a content type module, so I'm marking critical.

Comments

carlos8f’s picture

Status: Active » Needs review
StatusFileSize
new2.62 KB
new1.77 KB

Patch which engages the static cache on rebuilds as well, and uses an internal 'init' property to determine if the static cache has been set or not.

Attached 2 patches to illustrate the static problem.

Status: Needs review » Needs work

The last submitted patch, 993992-1-node-types-build.patch, failed testing.

carlos8f’s picture

Status: Needs work » Needs review
StatusFileSize
new2.68 KB
new1.82 KB

These should apply :)

carlos8f’s picture

StatusFileSize
new2.8 KB

Oh, of course resetting the static on $rebuild would be great, too!

Status: Needs review » Needs work

The last submitted patch, 993992-4-node-types-build.patch, failed testing.

carlos8f’s picture

Status: Needs work » Needs review
StatusFileSize
new2.21 KB

OK, it's clear that fixing that dysfunctional cache_set()/static relationship is a bigger problem, here we simply invalidate the static cache on a rebuild.

dries’s picture

Mmm. This is semantics not? If the node type is created during the current page request, I expect 'is_new' to be TRUE, even after it was saved. The behavior you want seems to be 'is_saved'.

carlos8f’s picture

According to the documentation of _node_types_build,

Both of these arrays will include new types that have been defined by hook_node_info() implementations but not yet saved in the {node_type} table. These are indicated in the type object by $type->is_new being set to the value 1.

So it seems that this flag is supposed to mean that the type is not saved yet, and exists in hook_node_info() only. That's important to know since queries will fail on the {node_type} table.

The usage of this flag in comment_install() may be misguided, I'm still trying to determine that. But attempting to unset the flag made me realize that _node_types_build() fails to reset its static cache, which could cause a lot of problems in itself.

carlos8f’s picture

Priority: Critical » Major

I've found a solution to #890128: Comment body missing if comment module enabled after a content type module that doesn't require this, so lowering priority appropriately. The static cache bug here could still cause headaches for contrib though.

David_Rothstein’s picture

Title: _node_types_build() fails to unset 'is_new' after saving a new type, and has static caching bugs » _node_types_build() labels content types 'is_new' when they're not, and has static caching bugs

I think this makes sense, based on the documentation.

Also, the first unset() in the patch definitely seems like it's heading in the right direction. Without that, content types like poll and blog which are defined in hook_node_info() always have $info->is_new set to TRUE, even when they are 8 months old or thereabouts :) However, I am wondering if there are times when we shouldn't unset that. Can there ever be a case where the info from hook_node_info() changes and therefore the database needs to be updated? I forget how this all works, what overrides what in that situation...

I'm also not sure I understand the test because with $this->resetAll() being called doesn't that mean that all caches are being cleared anyway so you're not actually testing the caching behavior of the function itself?

sun’s picture

Version: 7.x-dev » 8.x-dev
Priority: Major » Normal
Issue tags: +Needs backport to D7

is_new may be used by modules to trigger dependent actions/inserts for new content types though.

tpopham’s picture

I'm working toward a better spec (and implementation) for _node_type_build() over at #1268974: For disabled node types with 'base' != 'node_content', _node_types_build() does not return data about the type.. I'm more interested in testing precise logic against the existing codebase. Since _node_types_build() is private to the node module, I'd like to make it generic, useful, and filter its behavior at the public methods.

I changed the spec of is_new to

/* ...
 *     - is_new: The $type->is_new flag does not appear in the `node_type' table.
 *       The property gets set to 1 for node types implemented by
 *       hook_node_info() that did not appear in the `node_type' table at
 *       _node_types_build() entry. The property is left unset otherwise.
 */

I'm confused by

So it seems that this flag is supposed to mean that the type is not saved yet, and exists in hook_node_info() only. That's important to know since queries will fail on the {node_type} table.

If you're dependent on a type implemented under hook_node_info(), then you should call node_types_rebuild(), right? (I noticed such use in the forum module). Anyway, it seems to me the solution to this bug is fixing the spec.

Thanks for the pointer to the caching problem, btw.

kscheirer’s picture

Issue tags: -Needs backport to D7

#6: 993992-6-node-types-build.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 993992-6-node-types-build.patch, failed testing.

mgifford’s picture

Assigned: carlos8f » Unassigned
Issue summary: View changes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Status: Needs work » Closed (outdated)
Issue tags: +Bug Smash Initiative

_node_types_build() was removed in Jun 2013, see #111715: Convert node/content types into configuration.

Closing as outdated. If that is wrong, reopen the issue, by setting the status to 'Active', and add a comment.