Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

FileSize
1.68 KB

Maybe this results in prettier queries.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

How I ended up following this without ever seeing it I do not know. Does d.o auto-follow now when an issue is assigned to someone?

Either way, looks sane.

Berdir’s picture

@Crell: Yes.

chx’s picture

Assigned: Crell » chx
Damien Tournoud’s picture

Status: Reviewed & tested by the community » Needs work

We need to prepare this sub-query like we prepare all the others, and make sure that the arguments bubble up properly. It works in the test because the sub-query doesn't use any placeholders.

Berdir’s picture

Right.

I hope @chx wasn't already working on this, but here's an update that seems to work. Not 100% sure if this is implemented correctly. For some reason that I don't quite understand are we calling compile() on conditions both in execute() and in __toString(). Confirmed with expressions that compile() needs to be called before arguments() but I don't think it needs to be called twice.

I think converting all these database tests, or those that don't require hooks to unit tests or at least DrupalUnitTests would be a nice task, should speed up our tests quite a bit, there's a huge amount of test methods in there...

Crell’s picture

+++ b/core/modules/system/lib/Drupal/system/Tests/Database/UpdateComplexTest.php
@@ -132,4 +132,18 @@ function testUpdateOnlyExpression() {
+    $results = array_map('intval', db_query('SELECT priority FROM {test_task}')->fetchCol());
+    $this->assertIdentical(array(29), array_unique($results));

Now that I look more carefully (bad Crell!), why the array_unique() here? That changes what's coming back in ways we cannot detect, so you may get back more than one row and not realize it. If we have to do this it should be commented, because otherwise it seems wrong to me.

I am planning to convert the DB tests to UnitTests post-feature-freeze when I have time. Actually I'll only be converting one of them and setting up the rest as Novice tasks. :-) I've not done that yet because there's other issues messing with the DB, and that's totally not a feature-freeze-sensitive issue so I'm prioritizing my time.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community

Well, it looks sane, the db maintainers think it looks sane and their concerns have been addressed with tests. Lets do it.

chx’s picture

FileSize
2.31 KB

Although #7 is irrelevant -- it's not the number of rows, it's the contents of them -- I have rerolled the test to look the same as every other test method here.

Berdir’s picture

@Crell: Had to do something where I was actually able to make progress: #1839134: Convert database tests to (Drupal)UnitTestBase

Damien Tournoud’s picture

Status: Reviewed & tested by the community » Needs work

I hope @chx wasn't already working on this, but here's an update that seems to work. Not 100% sure if this is implemented correctly. For some reason that I don't quite understand are we calling compile() on conditions both in execute() and in __toString(). Confirmed with expressions that compile() needs to be called before arguments() but I don't think it needs to be called twice.

Right. It's because this grew organically. The way it is supposed to work(TM) is:

  • compile() should compile the main query and all its dependent objects
  • arguments() should return the arguments of the main query and all its dependent objects
  • execute() should be a simple:
    $this->preExecute();
    $this->compile($this->connection, $this);
    $this->connection->query((string) $this, $this->arguments(), $this->queryOptions);
    
  • __toString() should also call ->compile() so we support casting the query to a string outside a context (the (string) $query syntax)

Select is about implemented correctly (getArguments() is totally unnecessary and should go away, but that's it).

Also, we need to reimplement ->compiled() as ->compiled($queryPlaceholder) because we support multiple compilation on the same object now.

So, all that to say that we do need the compile in __toString().

Berdir’s picture

Status: Needs work » Needs review
FileSize
711 bytes
2.21 KB

Like this?

alexpott’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

We need a need for the addition to the __toString() functionality.

chx’s picture

Status: Needs work » Needs review
FileSize
1.08 KB
2.45 KB

Sure.

chx’s picture

FileSize
1.94 KB
2.82 KB

The test from #9 was lost. I rerolled with that one and added a string test.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

#15 looks great, it's addressed concerns from #11 and #7... and we've got full test coverage for all changed lines of code.

We're good to go here!

Damien Tournoud’s picture

Approved here.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

chx’s picture

Assigned: chx » Unassigned
Status: Fixed » Patch (to be ported)
Tor Arne Thune’s picture

Version: 8.x-dev » 7.x-dev
posulliv’s picture

Status: Patch (to be ported) » Needs review
FileSize
3.5 KB

Patch for D7. Also updated PostgreSQL driver for D7 with appropriate fix.

mgifford’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll
chx’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
0 bytes

Reroll.

chx’s picture

FileSize
3.5 KB

Try again.

Crell’s picture

+++ b/includes/database/pgsql/query.inc
@@ -174,6 +174,13 @@ class UpdateQuery_pgsql extends UpdateQuery {
+        $selectQueryArguments = $data['expression']->arguments();

No camelCase for non-object-member variables.

mgifford’s picture

Status: Needs review » Needs work
chx’s picture

Status: Needs work » Needs review
FileSize
3.5 KB

How hard it is to download the goddamn patch and edit it? You don't need to do anything else and then we do not hold up a patch that has been linger since 2012! You people.

chx’s picture

FileSize
3.5 KB
mgifford’s picture

Status: Needs review » Reviewed & tested by the community

This should be good then. Thanks for rerolling it @chx.

chx’s picture

FileSize
3.5 KB

postgresql had a typo.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: 1837118_23_0_1.patch, failed testing.

Status: Needs work » Needs review

chx queued 30: 1837118_23_0_1.patch for re-testing.

chx’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: 1837118_23_0_1.patch, failed testing.

Status: Needs work » Needs review

mgifford queued 30: 1837118_23_0_1.patch for re-testing.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: 1837118_23_0_1.patch, failed testing.

Status: Needs work » Needs review

chx queued 30: 1837118_23_0_1.patch for re-testing.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: 1837118_23_0_1.patch, failed testing.

Status: Needs work » Needs review

chx queued 30: 1837118_23_0_1.patch for re-testing.

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: 1837118_23_0_1.patch, failed testing.

Status: Needs work » Needs review

dcam queued 30: 1837118_23_0_1.patch for re-testing.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: 1837118_23_0_1.patch, failed testing.

Status: Needs work » Needs review

dcam queued 30: 1837118_23_0_1.patch for re-testing.

dcam’s picture

Status: Needs review » Reviewed & tested by the community
David_Rothstein’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Reviewed & tested by the community » Needs work
+        $select_query_arguments = $data['expression']->arguments();
+        foreach ($selectQueryArguments as $placeholder => $argument ){

This can't possibly work since the variable doesn't exist - perhaps it's the typo @chx intended to fix in #30?

More to the point, these PostgreSQL fixes aren't in Drupal 8... Let's get the issue fixed there first (and tested to make sure it actually works with the relevant database drivers), then backported.

David_Rothstein’s picture

Status: Needs work » Needs review
FileSize
833 bytes

UNTESTED, but presumably this is what it should look like for Drupal 8. I fixed the issue above (as well as a minor code style issue).

The code looks like it could also be simplified a fair amount (get rid of $select_query_arguments entirely; just use $argument) but this is consistent with the way the code above it is written, so I left that alone.

Crell’s picture

Component: database system » postgresql db driver

Refiling for the people who know Postgres, if any still pay attention to core...

mradcliffe’s picture

PostgreSQL test bot found this in the failing test: ComplexUpdateTest::testSubSelectUpdate().

bzrudi71’s picture

FileSize
8.26 KB

Just ran Database tests on PG testbot. Unfortunately there is still an exception, in Drupal\system\Tests\Database\UpdateComplexTest even with patch from #35 applied, see attached results.txt for a full test log.

mradcliffe’s picture

FileSize
6.81 KB
949 bytes

SelectQueryInterface is not in drupal 8. Should be SelectInterface. I needed to include the interface for the test to pass.

mradcliffe’s picture

FileSize
1 KB

Forgot to rebase like a scrub. Sorry, Crell.

Crell’s picture

Status: Needs review » Needs work

If I understand #53 correctly PG is already broken and this doesn't make it worse. However, the latest patch is missing the tests from earlier issues.

Fabianx’s picture

Status: Needs work » Needs review

I don't totally understand how binding works, so RTBC if tests pass and it has all tests to test that ...

mradcliffe’s picture

Status: Needs review » Closed (fixed)
Issue tags: -Needs backport to D7

Closing as fixed in Drupal 8 per Crell.

I will create a follow-up issue specifically for PostgreSQL Drupal 8 and Drupal 7. It also looks like this patch needs to be backported to Drupal 7 in general so I will create a follow-up issue on that.

- Hiding files that were added after issue was closed to be less confusing.

Fabianx’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

What is the process for PG SQL then?

It was not yet removed from core as much as I can see and we can ship it if:

a) tests pass

and

b) we have PG SQL test bots

So why closing that issue?

mradcliffe’s picture

Fabianx’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Okay, thanks. This is a duplicate then.

Crell’s picture

Status: Closed (duplicate) » Closed (fixed)
Fabianx’s picture

Status: Closed (fixed) » Closed (duplicate)

Sorry for playing ping-pong, but would like to know why: Closed (fixed) if there are other issues that are duplicates of this one?

Fabianx’s picture

Status: Closed (duplicate) » Closed (fixed)

Ah, something was fixed in this issue already - and committed. Makes more sense now.

Leaving as closed fixed then.