Skip to content

Importing existing entities re-adds statements #22

Open
Wikidata/WikibaseImport
#1

Description

@lucaswerkmeister

Depending on local setup, if you re-import entities that you’ve already imported before, the importer will add all the statements again, leaving you with duplicate statements.

This query in PagePropsStatementCountLookup::getStatementCount is the culprit:

     $res = $db->selectRow(
         array( 'page_props', 'page' ),
         array( 'pp_value' ),
         array(
             'page_namespace' => 0, // <-- HERE
             'page_title' => $entityId->getSerialization(),
             'pp_propname' => 'wb-claims'
         ),
         __METHOD__,
         array(),
         array( 'page' => array( 'LEFT JOIN', 'page_id=pp_page' ) )
     );

In a default Wikibase setup, Item is namespace #120, and Property is namespace #122 (see Wikibase/repo/config/Wikibase.example.php), so the query returns no result, which is interpreted as a statement count of 0:

     if ( $res === false ) {
         return 0;
     }

Even if you configure your Wikibase to put items in the main namespace, as on Wikidata, I think the importer would still duplicate statements on properties.

I’m not sure what the best way to solve this is, but perhaps it would be a good idea to throw an exception instead of returning 0 if the query returns no results: if we can’t find the entity, there must be something wrong, right?

Workaround: change the query to select, e. g., 'page_namespace' => [ 120, 122 ].

Activity

  1. lucaswerkmeister commented on Apr 21, 2017

    @lucaswerkmeister
    ContributorAuthor

    Wait, I forgot that this is a MediaWiki extension, so it has access to the same config that Wikibase uses, and can look up the entity namespaces :) fix incoming.

  2. added 3 commits that reference this issue on Apr 21, 2017
    4b143e4
    780cb00
    cbf97a6
  3. added a commit that references this issue on May 10, 2017
    f669157
  4. added a commit that references this issue on Apr 12, 2019
    307b44b
  5. D063520 commented on Jun 18, 2019

    @D063520

    I encountered the same problem, took me a morning to debug. I just dropped this line:
    'page_namespace' => 0,
    Why is the pull request not merged yet?
    How can I help accelerate this?

  6. jjkoehorst commented on Jul 8, 2019

    @jjkoehorst

    Any clue when / if this can be fixed? I am running into this sync issue as well...Would love to help but php is not my strongest point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions