Disallow reserved field names

bjaspan - February 24, 2009 - 16:12
Project:Drupal
Version:7.x-dev
Component:field system
Category:bug report
Priority:critical
Assigned:fgm
Status:closed
Issue tags:Fields in Core
Description

Field API should refuse to create field names that override other property names identified by fieldable info (e.g. for node: nid, vid, type). We may want to allow fieldable info to specify additional reserved names as well.

#1

bjaspan - March 7, 2009 - 14:40
Priority:normal» critical

#2

scor - March 18, 2009 - 21:50

would you hardcode that blacklist or generate it from looking at the fieldable info of a node?

#3

KarenS - March 19, 2009 - 08:07

Wouldn't it be more flexible to use a hook or callback for this so any module can specify names that should not be used? Maybe on a bundle by bundle basis (the name is OK on a page bundle but not OK on my custom bundle).

#4

fgm - March 19, 2009 - 11:31
Assigned to:Anonymous» fgm

I'm gonna try this one (see http://drupal.org/community-initiatives/drupal-core/fields)

I think some historical info may still need to be hardcoded, but the rest should be available from the fieldable info. Adding a hook or callback would likely add unneeded load for little benefit, as field creation is a statistically rare occurrence.

#5

bjaspan - March 19, 2009 - 13:05

Thanks, Frederic!

IIRC the motivation behind this issue was #367595: Translatable fields and the possible "language" property.

I'm not sure why a separate hook should be needed since hook_fieldable_info() can return a list. Do we want to call a hook for non-fieldable modules to return data about fieldable entity types? Seems odd.

We have to figure out what to do if a "reserved name" shows up in the banned list after a field with that name already exists.

Currently neither node nor user makes any attempt to prevent this kind of problem. If this turns into an impossible rathole, then we don't really have to deal with it either.

#6

KarenS - March 19, 2009 - 19:30

Field creation is a statistically rare occurrence, so doing a bit of extra work to make sure it is set up in a way that will create other problems has no big cost. And a field that uses a name that some other module expected to be able to use could create potentially significant problems, so it seems like it has a good cost-to-benefit ratio.

Sure it hasn't come up so far, but we're going down a path we've never been on before adding fields to everything and making all kinds of things that were not fields before into fields. I have no specific use case, but was thinking about something like a modules that work together to do complex processing (i.e. ecommerce or finance) that need to know that any fields with specific names are 'their' fields. And the Node module could protect 'body', 'teaser', and 'title' and the User module could protect 'name', 'mail', and 'password' as well using the same method.

We don't have to do this of course, but there is very little cost to creating a flexible way to let modules tells us what names are not 'allowable' instead of using a hard-coded list that later breaks something.

#7

yched - March 19, 2009 - 20:24

I'd tend to think the safest way to prevent those clashes is to promote naming conventions, like : 'prefix your fields with your module's name - if you don't do this, don't come crying'. Core-defined fields could possibly be a safe exception (body, teaser, title), for legacy's sake.

#8

KarenS - March 19, 2009 - 22:59

OK, I'll back down on this idea. Just thought it was worth exploring.

#9

bjaspan - March 20, 2009 - 19:35

I'm also thinking that per-module protected names only need to be protected (if they do at all) within an object type. e.g. suppose that node module protects title. Why should I not be able to create a field named title and just not attach it to nodes?

For object properties (such as 'language', if we end up using that) that apply to *every* object with fields attached, the Field API would flat out prohibit it as a field name. That was the original point of this issue.

Maybe we should hold off until we actually have such object properties used globally by field api.

#10

aaron - June 13, 2009 - 02:48

also need to think about what to do when adding a new module that reserves a name already in use. for instance, one creates a ->location field, then later installs the location module.

#12

yched - June 13, 2009 - 19:59

Re arron #10 : The fields added through the UI will all have a forced prefix (probably 'field_' to stay consistent with CCK D6 names)
Modules need to follow good practice and prefix the fields they create by the module name to avoid name clashes.

Note that we just made an exception with 'body' field (instead of 'node_body'). That's probably OK here (really more straightforward for this very common field), but that doesn't set contrib up for good practice...

#13

fgm - August 1, 2009 - 16:18
Status:active» needs work

OK, sorry it took me so long for so little, but here is a first attempt, just to make sure this is really what this request is about.

AttachmentSizeStatusTest resultOperations
382464.patch1.06 KBIdlePassed: 12893 passes, 0 fails, 0 exceptionsView details | Re-test

#14

fgm - August 4, 2009 - 20:17
Status:needs work» needs review

Rerolled with added simpletest.

AttachmentSizeStatusTest resultOperations
382464-1.patch2.07 KBIdleFailed: Failed to apply patch.View details | Re-test

#15

System Message - August 10, 2009 - 22:37
Status:needs review» needs work

The last submitted patch failed testing.

#16

fgm - August 11, 2009 - 16:21
Status:needs work» needs review

Rerolled against today's HEAD.

AttachmentSizeStatusTest resultOperations
382464-2.patch2.08 KBIdleFailed: 12658 passes, 1 fail, 0 exceptionsView details | Re-test

#17

bjaspan - August 13, 2009 - 01:09

I'm wondering if this whole issues counts as over-engineering, and we should just go with the plan in #7.

#18

System Message - August 22, 2009 - 15:50
Status:needs review» needs work

The last submitted patch failed testing.

#19

sun.core - August 22, 2009 - 16:21
Status:needs work» needs review

#20

System Message - August 26, 2009 - 12:15
Status:needs review» needs work

The last submitted patch failed testing.

#21

fgm - August 29, 2009 - 19:56
Status:needs work» needs review

Why did it suddently stop passing ?

#22

System Message - August 29, 2009 - 20:15
Status:needs review» needs work

The last submitted patch failed testing.

#23

fgm - September 5, 2009 - 10:22
Status:needs work» needs review

Revised version for today's head.

AttachmentSizeStatusTest resultOperations
382464-3.patch2.1 KBIdleFailed: Failed to apply patch.View details | Re-test

#24

System Message - September 5, 2009 - 10:37
Status:needs review» needs work

The last submitted patch failed testing.

#25

fgm - September 5, 2009 - 12:17
Status:needs work» needs review

Rerolled from root..

AttachmentSizeStatusTest resultOperations
382464-4.patch2.04 KBIdleFailed: Failed to apply patch.View details | Re-test

#26

System Message - September 5, 2009 - 12:36
Status:needs review» needs work

The last submitted patch failed testing.

#27

fgm - September 5, 2009 - 12:37
Status:needs work» needs review

Patch format problem. Grrr.

AttachmentSizeStatusTest resultOperations
382464-5.patch2.1 KBIdlePassed: 12901 passes, 0 fails, 0 exceptionsView details | Re-test

#28

fgm - September 5, 2009 - 13:20

I *think* the "Fields in core" tag needs to be added

#29

bjaspan - September 7, 2009 - 17:08
Status:needs review» reviewed & tested by the community

Code style cleanup, improved comment (we do not reference d.o issues in code), and slight test improvement (use test_entity, not node, as part of the test case). Otherwise, works.

AttachmentSizeStatusTest resultOperations
field-reserved-names-382464-29.patch2.47 KBIdlePassed: 12909 passes, 0 fails, 0 exceptionsView details | Re-test

#30

fgm - September 7, 2009 - 20:19

Minor nitpicking, but shouldn't we say ""...from the "test_entity" bundle" instead of "....from the "test_entity" type" ?

#31

bjaspan - September 8, 2009 - 04:01

No. The revision id key is defined by the entity type. A bundle is just a name for a collection of fields to load at once.

#32

webchick - September 11, 2009 - 03:42
Status:reviewed & tested by the community» fixed

Cool, I committed this to HEAD.

It's hard to tell from the replies above if we need to expand this out to cover more instances or not, but for now marking fixed.

#33

System Message - September 25, 2009 - 03:50
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.