file_space_used() not checking properly checking bitmapped status value (adds unit tests)

Josh Waihi - December 3, 2008 - 01:56
Project:Drupal
Version:7.x-dev
Component:file system
Category:bug report
Priority:critical
Assigned:drewish
Status:closed
Description

the shorthand 'status & :status' doesn't work on postgres. Postgres needs the comparison operator ' > 0' appended on the end

currently, File validator tests throws an Exception due to this.

patch simply appends the comparison on the end

AttachmentSizeStatusTest resultOperations
file.inc_.patch784 bytesIdleFailed: Failed to apply patch.View details | Re-test

#1

kaotien - December 3, 2008 - 02:01

Clean Drupal 7 install on MySQL

File -> File Validator tests

Pre-patch: 27 passes, 0 fails, and 0 exceptions
Post-patch: 27 passes, 0 fails, and 0 exceptions

#2

serenecloud - December 3, 2008 - 02:15
Status:needs review» reviewed & tested by the community

Testing with CVS HEAD and PostgreSQL 8.1

Without Patch:

SELECT SUM(filesize) FROM {files} WHERE uid = :uid AND status & :status - Array ( [:uid] => 3 [:status] => 1 ) SQLSTATE[42804]: Datatype mismatch: 7 ERROR: argument of AND must be type boolean, not type integer

After patch I ran the File SimpleTest:

215 passes, 0 fails, and 0 exceptions

Happy to mark this as reviewed.

#3

Dave Reid - December 3, 2008 - 05:05
Status:reviewed & tested by the community» needs work

Please use diff -up to create patches for core. See http://drupal.org/patch/create for more details.

#4

Dave Reid - December 3, 2008 - 05:31

Plus, are bitwise operators a SQL standard? I can't find if they are and if they're not, they should be replaced.

#5

Dave Reid - December 3, 2008 - 06:39

From system_schema, the {files}.status is simply an integer, so what reason do we have to do status & status > 0 instead of simply status > 0?

#6

Josh Waihi - December 4, 2008 - 00:56
Status:needs work» needs review

we couldn't do status > 0 because you should be able to find the filesize sum of a group of file with a particular status. FILE_STATUS_TEMPORARY = 0 which means with bitwise comparison, you could never find the total filesize for temporary files with this function. so I think a simple WHERE status = :status would be better and from testing that I've done, it faster than bitwise comparison not to mention easier to understand for most people.

AttachmentSizeStatusTest resultOperations
file.inc_.patch1.01 KBIdleFailed: Failed to apply patch.View details | Re-test

#7

Dave Reid - December 4, 2008 - 04:19
Status:needs review» reviewed & tested by the community

That's a much better, more easily understood solution. The bitwise was just too confusing. Passed tests, looks good and RTBC.

#8

Dries - December 4, 2008 - 11:09
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD.

#9

System Message - December 18, 2008 - 11:12
Status:fixed» closed

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

#10

drewish - December 24, 2008 - 07:00
Status:closed» needs work

Actually this is totally incorrect. The status field is documented as a bitmapped field not a simple integer I've been trying to get #330633: Temporary file cleanup needs some love (UnitTest included!) updated to check it correctly.

#11

drewish - December 24, 2008 - 07:01

Dave Reid, grrrrr... just realized you'd been commenting on the other issue. i wish you'd have linked the two up but at least now i've got a pgsql fix for the other issue.

#12

Dave Reid - December 24, 2008 - 14:20

Sorry drewish.

#13

drewish - December 24, 2008 - 18:01

no, i apologize. it's really my fault for keeping an eye on the queue and for not installing pgsql and addressing #330633: Temporary file cleanup needs some love (UnitTest included!) a month ago. seems like #339588: Column type of int_unsigned causing pdoexception might be at the root of this.

#14

drewish - December 25, 2008 - 04:10
Title:file_space_used SQL fails on Postgres» file_space_used() not checking properly checking bitmapped status value.
Status:needs work» postponed

marking this as postponed pending #339588: Column type of int_unsigned causing pdoexception. the attached patch works with pgsql once it's applied.

AttachmentSizeStatusTest resultOperations
file_341910.patch1.03 KBIdleUnable to apply patch file_341910.patchView details | Re-test

#15

drewish - December 26, 2008 - 19:53
Status:postponed» needs review

#16

Dries - December 28, 2008 - 19:18

Would be great if someone using PostgreSQL could run the tests with and without the latest patch. If this is PostgreSQL specific, I recommend adding PostgreSQL to the title.

#17

drewish - December 28, 2008 - 21:21

Dries, I ended up figuring out how to setup pgsql just to test this patch so I can say clearly that it works with both MySQL and PostgreSQL. At this point it's not a pgsql specific fix since the pgsql "fix" reverted the desired behavior.

#18

Dries - December 29, 2008 - 06:45

Well, but on MySQL there is no test failing with or without this patch. Does it mean that we don't have test coverage for this problem?

#19

drewish - December 29, 2008 - 22:24
Status:needs review» needs work

Right the tests don't create files with multiple statues. I'll expand the function's test.

#20

drewish - December 30, 2008 - 04:46
Status:needs work» needs review
AttachmentSizeStatusTest resultOperations
file_341910.patch4.22 KBIdleUnable to apply patch file_341910_0.patchView details | Re-test

#21

drewish - December 30, 2008 - 04:49
Title:file_space_used() not checking properly checking bitmapped status value.» file_space_used() not checking properly checking bitmapped status value (adds unit tests)

oh, forgot to add that the current code has zero tests for file_space_used(). I'm not sure how it was over looked. The current patch adds tests.

#22

Dries - December 30, 2008 - 15:51
Status:needs review» needs work

In the test code, can we stick to using the defines instead of integers? It would make the tests a lot easier to read/review, and it makes for better example code.

#23

drewish - December 30, 2008 - 17:56
Assigned to:Josh Waihi» drewish

Dries, 1 is the only core defined status and its constant is used. The other status values were arbitrarily selected for testing purposes. Are you suggesting that I should define constants in the test case? Or in core?

#24

drewish - December 31, 2008 - 18:28
Status:needs work» needs review

bumping back to CNR since i think the current tests are correct.

#25

Dries - January 4, 2009 - 19:12
Status:needs review» needs work

Nope, I'm not suggesting that you define constants for testing purpose. Maybe just add some more code comments to the test code. Explain why you are testing things this way, and mention that these values are arbitrarily selected. That should do it for me. Thanks!

#26

drewish - January 5, 2009 - 00:01

just a note that this issue needs to keep any eye on #352956: PDOException on install and use a similar fix.

#27

drewish - January 5, 2009 - 02:20
Status:needs work» needs review

Went ahead and converted this into a full DBTNG query. Added tests to the comments.

AttachmentSizeStatusTest resultOperations
file_341910.patch4.91 KBIdleUnable to apply patch file_341910_1.patchView details | Re-test

#28

Dries - January 5, 2009 - 07:16
Status:needs review» needs work

When I run the tests, I get 2 failures:

Found the size of the first user's files with status 8.1	Other	file.test	188	FileSpaceUsedTest->testUserAndStatus()	
Found the size of the first user's files with status 2.	1	file.test	189	FileSpaceUsedTest->testUserAndStatus()

#29

drewish - January 6, 2009 - 00:35
Status:needs work» needs review

sorry about that. it looks like i'd just re-submitted the last patch. here's the correct version.

AttachmentSizeStatusTest resultOperations
file_341910.patch4.76 KBIdleUnable to apply patch file_341910_2.patchView details | Re-test

#30

Dries - January 6, 2009 - 12:00
Status:needs review» fixed

Committed to CVS HEAD. Thanks all!

#31

System Message - January 20, 2009 - 12:10
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.