Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Needs review » Postponed (maintainer needs more info)

There should be no empty bundle strings in File entity 7.x-1.x. What would cause this?

Dave Reid’s picture

As a clarification we add a file type if it is not set in hook_file_presave(), we have an update function that should cover any files that were uploaded prior to file_entity, and the default if the file type is undetermined is 'application/octet-stream'.

chx’s picture

Project: File Entity (fieldable files) » D7 Media
Priority: Normal » Critical
Status: Postponed (maintainer needs more info) » Needs review

Also note that if the type is undetermined then my patch is still not adequate -- there needs to be a fallbakc for undefined.

And the problem is with media, not file_entity. Moving there. Despite what effulgentsia said this patch is against the latest 7.x-1.x ( http://drupalcode.org/project/media.git/blob/refs/heads/7.x-1.x:/file_en... ) which doesnt http://drupalcode.org/project/media.git/blob/refs/heads/7.x-1.x:/file_en... have an update function to supply type. Should we backport that from file_entity, then, instead?

chx’s picture

effulgentsia’s picture

I'm about to be on vacation for a week, so won't be able to see this through during that time. If people find solutions that work for them, that's great, so for anyone interested, please keep this issue and/or #1266620: Missing bundle property on entity of type file error going as you see fit.

A difference between Media 1.x and 2.x though is that in 1.x, it's the Media module that has some legacy logic for determining the type of a file, and in 2.x, that has been moved upstream to the File Entity module. I'm a little hazy right now on how to best adjust Media 1.x to match the requirement of no empty type. There's a couple issues to consider, but nothing I can coherently express right now. Anyway, I encourage people to experiment as needed, or else apply #1067750-49: Let Field API fail in a tale-telling way on invalid $entity to your local core installations as a stop-gap.

Starminder’s picture

+1

Dave Reid’s picture

Yeah the problem here is that the logic to determine what type of file it is isn't based on mimetype - its based on file_get_type() which can return a NULL value. I think this is part of a larger problem that we could fix in 7.x-2.x properly but is wound up in legacy code in 7.x-1.x.

Dave Reid’s picture

Thinking...what if we added something like this:

function media_file_load($files) {
  foreach ($files as &$file) {
    if (empty($file->type)) {
      $file->type == 'file';
    }
  }
}
chx’s picture

#8 that's what #3 said Also note that if the type is undetermined then my patch is still not adequate -- there needs to be a fallbakc for undefined.

Just make sure it's not something that's defined as a bundle. I think 'undefined' works better than 'file'.

Dave Reid’s picture

The default bundle string for entities with no bundle is the entity type itself (e.g. bundle for user entities is 'user'), so that's why I went with 'file'. Also we'd need to ensure that we're not saving 'file' as {file_managed}.type when calling file_save() so that we get a chance to save the proper file type (tl;dr we need to adjust file_entity_file_presave() to check if $file->type == 'undefined').

j.slemmer’s picture

sub...

Starminder’s picture

Any ideas? I can't seem to disable media module, I have a field using it. Just had this happen trying to rebuild content access perms.

An error has occurred.
Please continue to the error page
An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?id=469&op=do StatusText: Service unavailable (with message) ResponseText: EntityMalformedException: Missing bundle property on entity of type file. in entity_extract_ids() (line 7389 of /home/hoslot5/public_html/includes/common.inc).

The content access permissions have not been properly rebuilt.

So, my site is kind of toast for anonymous users. I'm open to quick and dirty suggestions for now :) Thanks!!

femrich’s picture

Seems I am in the same position as Starminder--rebuilt permissions, got the same error, and now when I try to uninstall media modules I get a timeout error--only situation in which that seems to happen at the moment on my site. Watching for solutions...

femrich’s picture

After unsuccessfully trying patching, I have resolved this temporarily by reverting to drupal 7.7. Will watch for updates to core and relevant modules...

Thomas Bosviel’s picture

Subscribe

Starminder’s picture

Applied the one-liner patch from here: http://drupal.org/node/1266620 and it solved my permissions issue.

Dave Reid’s picture

.

Dave Reid’s picture

Assigned: Unassigned » effulgentsia
effulgentsia’s picture

Assigned: effulgentsia » Unassigned
FileSize
4.19 KB

This solves it as far as I know. If anyone finds a use-case that it doesn't handle, please comment. Thanks.

JacobSingh’s picture

Status: Needs review » Needs work

To summarize and make sure I got this straight. The goal here is just to stop using an empty string for an undefined media type and start using FILE_TYPE_NONE, right?

+++ b/file_entity/file_entity.file_api.incundefined
@@ -5,6 +5,14 @@
+define('FILE_TYPE_NONE', 'und');

Do you think this might cause more confusion then just having something unique?

+++ b/includes/media.types.incundefined
@@ -242,7 +242,7 @@ function media_media_format_form_prepare_alter(&$form, &$form_state, $file) {
 function media_type_invalid_files_count() {
   return db_select('file_managed', 'fm')
-    ->condition('type', '')
+    ->condition('type', FILE_TYPE_NONE)
     ->countQuery()
     ->execute()
     ->fetchField();
@@ -267,7 +267,7 @@ function media_type_batch_update($update_existing = FALSE, $no_to_update = NULL,

@@ -267,7 +267,7 @@ function media_type_batch_update($update_existing = FALSE, $no_to_update = NULL,
     ->fields('fm', array('fid'));
 
   if (!$update_existing) {
-    $query->condition('type', '');
+    $query->condition('type', FILE_TYPE_NONE);

How will this handle files which are already in someones' DB which have no type? won't they be in limbo forever?

JacobSingh’s picture

Status: Needs work » Reviewed & tested by the community
Dave Reid’s picture

As a follow-up (or included here) we should patch file_entity to use a proper menu loader for bundle menu items (e.g. %file_type_load rather than using just '%' in the menu paths).

chx’s picture

Status: Reviewed & tested by the community » Needs work

FILE_TYPE_NONE is a good constant but the value really should be just file or something but not und. und is from the ISO 639-2 standard for undetermined language you can't just that for a file.

JacobSingh’s picture

@chx: I didn't love this, but tbh, it's only going to last in 1.x and is already replaced in 2.x (which everyone will be upgrading to as soon as possible). So it's really not a huge deal. Do you have another suggestion?

chx’s picture

We have agreed on 'undefined' on IRC quickly

effulgentsia’s picture

Status: Needs work » Needs review
FileSize
7.2 KB

Thanks for the reviews. This addresses #22 and #23.

becw’s picture

Assigned: Unassigned » becw

Reviewing.

effulgentsia’s picture

Assigned: becw » Unassigned
FileSize
7.47 KB
+++ b/file_entity/file_entity.install
@@ -14,7 +14,7 @@ function file_entity_schema_alter(&$schema) {
+    'default' => FILE_TYPE_NONE,

I don't know if there's any situation in which hook_schema_alter() can be called without the .module file loaded, but in case there is, this patches uses the literal instead of the constant here.

effulgentsia’s picture

Assigned: Unassigned » becw

sorry. didn't mean to unassign becw.

becw’s picture

Status: Needs review » Reviewed & tested by the community

This patch looks good to me. Tests run, the update function runs, and the code looks fine. RTBC for 7.x-1.x

As far as I can tell from the discussion above, undefined file types are already handled in 7.x-2.x and the independent File Entity module. We should still add the update function (file_entity_update_7002()) to the independent File Entity module.

becw’s picture

Assigned: becw » Unassigned
effulgentsia’s picture

Status: Reviewed & tested by the community » Fixed

Woohoo! Committed to 7.x-1.x.

Carlos Miranda Levy’s picture

Status: Fixed » Needs review
Issue tags: -D7 stable release blocker

Status: Needs review » Needs work
Issue tags: +D7 stable release blocker

The last submitted patch, media-file-type-und-1268378-28.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Fixed

Please don't do that for fixed issues.

Status: Fixed » Closed (fixed)

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

jerrac’s picture

I'm using Media 7.x-1.x-dev released on 2011-Oct-16. As well as the bundled File Entity module. Even though the patch from #28 is committed, I still get this error when browsing admin/content:

EntityMalformedException: Missing bundle property on entity of type file. in entity_extract_ids() (line 7405 of /home/reagand/devcloud/siteadmin/docroot/includes/common.inc).

Dave Reid said that http://drupal.org/node/1266620 is a duplicate of this issue, which is why I'm posting here instead of there.

I'm on Drupal 7.8.

I tried upgrading to 7.x-dev, but it didn't seem to do anything.

I tried running admin/config/media/rebuild_types.

When I first enabled File Entity, it gave me this error:

DatabaseSchemaObjectExistsException: Table file_display already exists. in DatabaseSchema->createTable() (line 652 of /home/reagand/devcloud/siteadmin/docroot/includes/database/schema.inc).

Does that have something to do with it? That error never showed up again, and File Entity stayed enabled. So I think it's installed fine.

I had Styles installed and enabled, but I've disabled all it's modules and uninstalled them.

That's everything I can think of right now. Is there any other information I can post that would help? Or steps I can take?

ezeedub’s picture

Title: Empty file type causes exceptions in Drupal 7.8 » Empty file type causes exceptions in Drupal 7.10
Version: 7.x-1.x-dev » 7.x-1.0-rc1
Status: Closed (fixed) » Active

Not sure about the new title/status, etc..

I just got this error earlier today upgrading D6 to D7...

$ drush en -y emfield
The following extensions will be enabled: emfield, media_internet, file_entity, media
Do you really want to continue? (y/n): y
WD system: file_entity module installed.                                  [info]
WD system: file_entity module enabled.                                    [info]
WD php: EntityMalformedException: Missing bundle property on entity
of type file. in entity_extract_ids() (line 7410 of /home/ed/workspace/DigitalOceanD7/drupal/includes/common.inc).  [error]

Just to be sure, I ran the upgrade a second time without relying on drush's automatic downloading and enabling of required modules.

drush en -y media
Initialized Drupal 7.10 root directory at                               [notice]
/home/ed/workspace/DigitalOceanD7/drupal
Initialized Drupal site default at sites/default                        [notice]
The following extensions will be enabled: media, file_entity
Do you really want to continue? (y/n): y
WD system: file_entity module installed.                                  [info]
WD system: file_entity module enabled.                                    [info]
WD php: EntityMalformedException: Missing bundle property on entity  [error]
of type file. in entity_extract_ids() (line 7410 of
/home/ed/workspace/DigitalOceanD7/drupal/includes/common.inc).
Cannot modify header information - headers already sent by (output [warning]
started at /usr/share/php/drush/includes/drush.inc:596)
bootstrap.inc:1221
EntityMalformedException: Missing bundle property on entity of type file. in entity_extract_ids() (line 7410 of /home/ed/workspace/DigitalOceanD7/drupal/includes/common.inc).
Drush command terminated abnormally due to an unrecoverable error.  [error]

Drupal 7.10, Media 1.0-rc2. Looks like I've got the patch in #28 (just in case I tried with 1.x-dev, same error).

Did this get re-introduced somehow or is this a different bug? Thx.

ajeancharles’s picture

FileSize
198.74 KB

I manually made the updates to the media module. I am not getting that error any more.
I want to submit my changes, however I don't quite grasp the process. It seems very opaque and more complicated than necessary.

Anybody interested in my version, to upload or what not is welcome to it.
I have attached the fixed module below.
If someone can show me the in's and out's in doing some of the maintenance, i will certainly help.

Regards

bryancasler’s picture

Version: 7.x-1.0-rc1 » 7.x-1.0-rc3

Got these notices on a fresh install...

Notice: Use of undefined constant FILE_TYPE_NONE - assumed 'FILE_TYPE_NONE' in media_type_invalid_files_count() (line 245 of C:\xampp\htdocs\playground5\sites\all\modules\media\includes\media.types.inc).

Notice: Use of undefined constant FILE_TYPE_NONE - assumed 'FILE_TYPE_NONE' in media_type_batch_update() (line 270 of C:\xampp\htdocs\playground5\sites\all\modules\media\includes\media.types.inc).
volocuga’s picture

Same here, using latest dev of 7.1 branch
Can not even enable the module

Taxoman’s picture

#41: which Drupal version was that against? (interesting, now that 7.11 and 7.12 was just released)

volocuga’s picture

@Taxoman: just updated to d 7.12 The error still here

David_Rothstein’s picture

Title: Empty file type causes exceptions in Drupal 7.10 » Empty file type causes exceptions in Drupal 7.8
Status: Active » Closed (fixed)

It seems unlikely that any remaining errors are due to empty file types, which is the original topic of this issue. Or at least, no one has provided any evidence that they are.

Therefore, I'm closing this again; if anyone can debug this to the point where they can prove that it is actually due to an empty file type, feel free to reopen; otherwise, the bug you're encountering is most likely some other issue. For example, I've encountered some EntityMalformedException errors as well, but it's not due to this issue; rather, it's due to #1426820: Fix Notices and EntityMalformedException if FID is not in the file_managed database table which is different.

Regarding @animelion's comment in #40 (about PHP notices due to undefined FILE_TYPE_NONE), that constant is defined by the File Entity module which is a dependency of Media, so it's hard to see how that can happen unless something went wrong and somehow the File Entity module never got enabled? If that is reproducible, it should be filed as a separate issue, though, rather than here.

camdarley’s picture

@animelion in comment#40: I fixed this issue here: http://drupal.org/node/1450260

HongPong’s picture

This may be a tangent but if you have malformed files entities - see #1446440: Unable to view me media management pages (EntityMalformedException: Missing bundle property...) for my one-off SQL fix for column type in the files_managed table. Seems like some checker could fix this.

saltednut’s picture

Unsure if this will help anyone else but I was having trouble with this. It turns out either myself or drush did a poor job picking dependencies.

The site has file_entity 2.x under sites/all/modules/file_entity - but it also had media 1.x and file_entity 1.x under sites/all/modules/media/file_entity

Removing the file_entity 2.x caused numerous errors - so it looks like this is the one that was enabled.

I replaced the 1.x media with 2.x unstable and it seems to have solved my errors. It initially threw a nice bit of exceptions about the old instances of file_entity 1.x - so maybe both were considered enabled? Strange.

I was able to clear cache and those errors went away though.

Running update.php did a few install hooks. Seems to be working now using media 2.x / file_entity 2.x with no reported issues.

In short: make sure you don't download the wrong version of file_entity and mix-match accidentally. The modules page might even report using 1.x but if there are two versions of file_entity floating around, you will see bogus errors like the one reported in #1.

ressa’s picture

I got this error after executing drush dl media wysiwyg and drush en -y media wysiwyg:

WD php: EntityMalformedException: Missing bundle property on entity  [error]
of type file. in entity_extract_ids() (line 7562 of
/srv/www/website/includes/common.inc).
Cannot modify header information - headers already sent by (output   [warning]
started at /usr/share/php/drush/includes/output.inc:37)
bootstrap.inc:1239
EntityMalformedException: Missing bundle property on entity of type file. in entity_extract_ids() (line 7562 of /srv/www/website/includes/common.inc).
Drush command terminated abnormally due to an unrecoverable error.   [error]

The installation didn't go through, there was no 'Wysiwyg profiles' menu point under 'Configuration' > 'Content authoring'. Uninstalling and reinstalling the Media module fixed it, and the Wysiwyg now works.

Module versions
Entity: 7.x-1.0-rc3
Media: 7.x-1.2
Wysiwyg: 7.x-2.2