Page MenuHomePhabricator

Make declarations for 25,000 CC BY-SA images
Closed, ResolvedPublic1 Estimated Story Points

Description

Event Timeline

Started job for this with resources: mem: 1.0Gi, cpu: 3.0.

This time 1,055 did not have ISCC generated. 1,029 were not errors, but rather duplicates of files already in the database. The job took six hours.

Files with errors (35 in total):

  • Charit%C3%A9_%28Berlin%29.jpg
  • Klobuersten_fcm.JPG
  • Gaenselieselbrunnen_%28fcm%29.jpg
  • Gaenselieselbrunnen_%28fcm%29.jpg
  • Batschkapp_%28fcm%29.jpg
  • Batschkapp_%28fcm%29.jpg
  • Batschkapp_%28fcm%29.jpg
  • Batschkapp_%28fcm%29.jpg
  • Gummistiefel_bunt_%28fcm%29.jpg
  • Gummistiefel_bunt_%28fcm%29.jpg
  • Cyatophyllum_sp.1_-_Devonico.JPG
  • Graureiher_1_%28fcm%29.jpg
  • Graureiher_1_%28fcm%29.jpg
  • Disque_perso-Antenne_ACROPOL_Sembert_1.JPG
  • Disque_perso-Antenne_ACROPOL_Sembert_2.JPG
  • Unknown_plant-79.jpg
  • Bimbo_veikro_A.JPG
  • Bimbo_veikro_B.JPG
  • Boca_de_lamprea.1_-_Aquarium_Finisterrae.JPG
  • Zabytkowa_kamiennica_Ch-no.JPG
  • Tebby.JPG
  • POL_Ustka_ul_Le%C5%9Bna_100-0223.JPG
  • Copy_of_SAN_118.jpg
  • Copy_of_SAN_109.jpg
  • MAAC.JPG
  • McArthur_Mills_ON.JPG
  • Mercedes_de_la_Roncha.JPG
  • Russell_Peters_-_Toronto_-_July_2007.JPG
  • JosephWershba.jpg
  • Graureiher_3_%28fcm%29.jpg
  • Graureiher_3_%28fcm%29.jpg
  • LDeleidi01.JPG
  • LDeleidi02.JPG
  • ClemensReif.jpg
  • Santiagopasarela.jpg

At least some of the duplicates come from T396124: Make 1,000 declarations. I had a look at the qurey for those and it looks like that also is for CC-BY-SA. @Ainali, can you double check this? On the wiki page it says "Exempel-query på 1 000 bilder med CC0 licens: https://w.wiki/EEgJ".

At least some of the duplicates come from T396124: Make 1,000 declarations. I had a look at the qurey for those and it looks like that also is for CC-BY-SA. @Ainali, can you double check this? On the wiki page it says "Exempel-query på 1 000 bilder med CC0 licens: https://w.wiki/EEgJ".

Oh yes, the text was wrong, it does indeed query for BY-SA images (I have updated the wiki page now).

I actually had a look at the failed files and there are a few duplicates. E.g. Gaenselieselbrunnen_%28fcm%29.jpg
Gaenselieselbrunnen_%28fcm%29.jpg

Some even occur four times:
Batschkapp_%28fcm%29.jpg
Batschkapp_%28fcm%29.jpg
Batschkapp_%28fcm%29.jpg
Batschkapp_%28fcm%29.jpg

This may have something to do with the query following redirects. @Ainali, can you update the query so it only lists unique filesname?

It's apparently a bug in the Commons SPARQL data, see for example this: https://w.wiki/Egiu that shows multiple schema:contentSize, schema:contentUrl and schema:url for the same entity.

And as far as I know, it's not possible to exclude redirects in the SPARQL query.

I've started a job on Toolforge to make these declarations. It'll run with a rate of max one request per 2 s.

Most (20,453) of the declarations had errors. 3,512 were successfully ingested. Most of the errors (20,375) were due to database issues. 75 were due to failures collecting metadata.

It looks like the first error was for file 3,591:

2025-08-25 17:51:16,319;__main__;ERROR;Error while processing file: 'File:Northbound Bakerloo Line platform at Waterloo 03.jpg'.
Traceback (most recent call last):
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1963, in _exec_single_context
    self.dialect.do_execute(
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 943, in do_execute
    cursor.execute(statement, parameters)
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/cursors.py", line 153, in execute
    result = self._query(query)
             ^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/connections.py", line 563, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/connections.py", line 825, in _read_query_result
    result.read()
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/connections.py", line 1199, in read
    first_packet = self.connection._read_packet()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/connections.py", line 744, in _read_packet
    packet_header = self._read_bytes(4)
                    ^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/connections.py", line 798, in _read_bytes
    raise err.OperationalError(
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/workspace/src/make_declaration.py", line 184, in <module>
    added_to_registry = process_file(
                        ^^^^^^^^^^^^^
  File "/workspace/src/make_declaration.py", line 110, in process_file
    journal.update_declaration(declaration, ingested_cid=cid)
  File "/workspace/src/declaration_journal.py", line 116, in update_declaration
    self._session.commit()
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2032, in commit
    trans.commit(_to_root=True)
  File "<string>", line 2, in commit
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
    ret_value = fn(self, *arg, **kw)
                ^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1313, in commit
    self._prepare_impl()
  File "<string>", line 2, in _prepare_impl
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
    ret_value = fn(self, *arg, **kw)
                ^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1288, in _prepare_impl
    self.session.flush()
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4345, in flush
    self._flush(objects)
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4480, in _flush
    with util.safe_reraise():
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 224, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4441, in _flush
    flush_context.execute()
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 466, in execute
    rec.execute(self)
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 642, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 85, in save_obj
    _emit_update_statements(
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 912, in _emit_update_statements
    c = connection.execute(
        ^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1415, in execute
    return meth(
           ^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 523, in _execute_on_connection
    return connection._execute_clauseelement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1637, in _execute_clauseelement
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1842, in _execute_context
    return self._exec_single_context(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1982, in _exec_single_context
    self._handle_dbapi_exception(
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2351, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1963, in _exec_single_context
    self.dialect.do_execute(
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 943, in do_execute
    cursor.execute(statement, parameters)
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/cursors.py", line 153, in execute
    result = self._query(query)
             ^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/connections.py", line 563, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/connections.py", line 825, in _read_query_result
    result.read()
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/connections.py", line 1199, in read
    first_packet = self.connection._read_packet()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/connections.py", line 744, in _read_packet
    packet_header = self._read_bytes(4)
                    ^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/pymysql/connections.py", line 798, in _read_bytes
    raise err.OperationalError(
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query')
[SQL: UPDATE declaration SET updated_timestamp=%(updated_timestamp)s, ingested_c:
id=%(ingested_cid)s WHERE declaration.id = %(declaration_id)s]
[parameters: {'updated_timestamp': datetime.datetime(2025, 8, 25, 17, 41, 17, 117067), 'ingested_cid': 'bbqjcamqyvu467ebewf4mc5z5iycyebrimjzlmkcnardwbli2iseqqmtf', 'declaration_id': 54583}]
(Background on this error at: https://sqlalche.me/e/20/e3q8)

Every subsequent file causes an error when trying to read from the database:

2025-08-25 17:51:17,944;__main__;ERROR;Error while processing file: 'File:Westbound Jubilee Line platform at Waterloo.jpg'.
Traceback (most recent call last):
  File "/workspace/src/make_declaration.py", line 184, in <module>
    added_to_registry = process_file(
                        ^^^^^^^^^^^^^
  File "/workspace/src/make_declaration.py", line 37, in process_file
    declaration = journal.get_page_id_match(page.pageid)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/src/declaration_journal.py", line 128, in get_page_id_match
    declaration = self._session.scalars(statement).one_or_none()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2473, in scalars
    return self._execute_internal(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2241, in _execute_internal
    conn = self._connection_for_bind(bind)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2110, in _connection_for_bind
    return trans._connection_for_bind(engine, execution_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 2, in _connection_for_bind
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 103, in _go
    self._raise_for_prerequisite_state(fn.__name__, current_state)
  File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 973, in _raise_for_prerequisite_state
    raise sa_exc.PendingRollbackError(
sqlalchemy.exc.PendingRollbackError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query')
[SQL: UPDATE declaration SET updated_timestamp=%(updated_timestamp)s, ingested_cid=%(ingested_cid)s WHERE declaration.id = %(declaration_id)s]
[parameters: {'updated_timestamp': datetime.datetime(2025, 8, 25, 17, 41, 17, 117067), 'ingested_cid': 'bbqjcamqyvu467ebewf4mc5z5iycyebrimjzlmkcnardwbli2iseqqmtf', 'declaration_id': 54583}]
(Background on this error at: https://sqlalche.me/e/20/e3q8) (Background on this error at: https://sqlalche.me/e/20/7s2a)

I ran the same batch without any of the errors above. A total of 24,905 declarations made over two runs.

I also changed so that the whole run will be stopped if there is a PendingRollbackError. This means it won't try (and fail) to make the remaining declarations. There's probably a more elegant way to solve this, but for now starting a new job works.