Problem/Motivation

Proposed resolution

Remaining tasks

User interface changes

API changes

Comments

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new14.82 KB

.

Status: Needs review » Needs work

The last submitted patch, 1: router-2338747-1.patch, failed testing.

Crell’s picture

I don't know what the point is without an issue summary.

  1. +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php
    @@ -97,7 +101,7 @@ public function dump(array $options = array()) {
    -      $this->connection->delete($this->tableName)->execute();
    +      $this->safeDatabaseExecute($this->connection->delete($this->tableName))->execute();
    

    This feels very weird. I don't have a more specific word for it off hand. :-) Rather, this operation should be encapsulated into ensureTableIsReady() or something, which will create it if it doesn't exist, truncate it if it does, etc.

  2. +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php
    @@ -161,4 +165,110 @@ public function getRoutes() {
    +    catch (\Exception $e) {
    +      // If there was an exception, try to create the table.
    +      if ($this->ensureTableExists()) {
    +        return $query->execute();
    +      }
    +      // Some other failure that we can not recover from.
    +      throw $e;
    +    }
    

    There's a very specific exception thrown for missing table. Just catch that, then you don't need the re-throw.

dawehner’s picture

Well, I just applied a technique used in the MenuTreeStorage.

This feels very weird. I don't have a more specific word for it off hand. :-) Rather, this operation should be encapsulated into ensureTableIsReady() or something, which will create it if it doesn't exist, truncate it if it does, etc.

Well, the great advantage of this technique is that you don't require runtime overhead and you don't have to care about.

There's a very specific exception thrown for missing table. Just catch that, then you don't need the re-throw.

A great.

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new14.68 KB

Rerolled. Review is not addressed but this has a higher chance of passing as it now passes the actual query objects to safeDatabaseExecute and doesn't want to execute the result either.

Status: Needs review » Needs work

The last submitted patch, 5: 2338747_5.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new15.14 KB
new1.16 KB

This could be it.

Status: Needs review » Needs work

The last submitted patch, 7: 2338747-7.patch, failed testing.

chx’s picture

Status: Needs work » Postponed
mgifford’s picture

dawehner’s picture

Status: Postponed » Needs review
StatusFileSize
new13.15 KB

There we go, a new patch, especially based upon the comment https://www.drupal.org/node/2371709#comment-10376429

Status: Needs review » Needs work

The last submitted patch, 11: 2338747-11.patch, failed testing.

The last submitted patch, 11: 2338747-11.patch, failed testing.

dawehner’s picture

Mh, too bad.

dawehner’s picture

Most of the advantages of this patch is already solved by #2605684: Routing silently fails in kernel tests

dawehner’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs work » Needs review
StatusFileSize
new16.85 KB

New version of it.

Status: Needs review » Needs work

The last submitted patch, 16: 2338747-16.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new43.75 KB
new30.67 KB

New version, this time it should also apply.

Status: Needs review » Needs work

The last submitted patch, 18: 2338747-18.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new44.49 KB
new764 bytes

There we go.

Crell’s picture

  1. +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php
    @@ -162,4 +167,111 @@ public function getRoutes() {
    +  protected function safeDatabaseExecute(Query $query) {
    

    The method name here is seriously weird. "safe" execute is right up there with "safe mode" or "mysql_no_really_for_reals_escape_string" as a name that is a code smell as it lacks context. :-)

    As noted in an earlier comment, the model here is weird. This is off the critical path, so ensureTable() would typically add one very simple query to a rare operation that is already several hundred queries; ie, it wouldn't be noticeable.

    If we want to stick to the catch-exception approach, then we need a better name here that is more self-descriptive. I am also tempted to say that the table definition should be passed in as well, as we were discussing in the DB issue, but in context that may not be necessary as a one-off.

  2. +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php
    @@ -162,4 +167,111 @@ public function getRoutes() {
    +  protected static function schemaDefinition() {
    

    There's no value to this being static, so don't make it static.

dawehner’s picture

StatusFileSize
new4.24 KB
new45.45 KB

Yeah I guess we could get rid of the method, it is not really helpful, especially because its just used by one method basically.

Status: Needs review » Needs work

The last submitted patch, 22: 2338747-22.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new44.97 KB
new491 bytes

Just a merge conflict.

Crell’s picture

  1. +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php
    @@ -97,7 +101,13 @@ public function dump(array $options = array()) {
    +      catch (\Exception $e) {
    +        $this->ensureTableExists();
    +      }
    

    Should this catch be more specific than a Pokemon exception? Just database exceptions, for instance?

    (The same applies elsewhere in the patch.)

  2. +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php
    @@ -162,4 +172,85 @@ public function getRoutes() {
    +        $this->connection->schema()->createTable($this->tableName, static::schemaDefinition());
    

    Since schemaDefinition() is no longer static, we can't call it this way. It should error. Just $this->schemaDefinition().

Other than those fairly small nits, this looks good.

dawehner’s picture

StatusFileSize
new44.97 KB
new655 bytes

Thank you for the quick review crell!

Should this catch be more specific than a Pokemon exception? Just database exceptions, for instance?

(The same applies elsewhere in the patch.)

Well, this is the approach we went with on all the lazy table issues.

Since schemaDefinition() is no longer static, we can't call it this way. It should error. Just $this->schemaDefinition().

Sure, let's go with it.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

OK, split the difference. Thanks, dawehner!

tstoeckler’s picture

Since schemaDefinition() is no longer static, we can't call it this way. It should error.

You wish... :-)

dawehner’s picture

Thank you @crell!

catch’s picture

Status: Reviewed & tested by the community » Fixed

There's no 'table doesn't exist exception' that can be reliably used across sqlite, mysql, postgres - we tried that in the original issue that added this pattern.

Patch looks great. Committed/pushed to 8.1.x, thanks!

  • catch committed a3f5ca8 on 8.1.x
    Issue #2338747 by dawehner, chx: Move {router} out of system.install and...
klausi’s picture

This change broke Rules tests in interesting ways and we need to have Drupal version switches now in some tests, because our tests run on both branches.

A change notice would have been nice when we make test breaking changes like this.

dawehner’s picture

Status: Fixed » Closed (fixed)

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