pyinat / naturtag

Tag your nature photos with iNat taxonomy and observation metadata
https://naturtag.readthedocs.io
MIT License
37 stars 4 forks source link

no such table: taxon error from 0.7 release #262

Closed andrew-taylor closed 1 year ago

andrew-taylor commented 1 year ago

Really useful program - thanks- but 0.7 breaks for me (see below), will explore 0.6.1 - again thanks for this

$ pip install naturtag==0.6.1
$ $ echo 0|naturtag -t 'indigo bunting'|tail
Choice: taxonomy:kingdom=Animalia
taxonomy:phylum=Chordata
taxonomy:subphylum=Vertebrata
taxonomy:class=Aves
taxonomy:order=Passeriformes
taxonomy:family=Cardinalidae
taxonomy:genus=Passerina
taxonomy:species=Passerina cyanea
inaturalist:taxon_id=10227
dwc:taxonID=10227
$ pip install naturtag==0.7
$ $ naturtag -t 'indigo bunting'
Multiple matches found for "indigo bunting"; please choose one:

  #   Rank      Name                             Common name                     
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 
  0   species   🐦 Passerina cyanea              Indigo Bunting                  
  1   hybrid    🐦 Passerina amoena × cyanea     Lazuli × Indigo Bunting         
  2   hybrid    🐦 Passerina caerulea × cyanea   Blue Grosbeak × Indigo Bunting  

Choice: 0
Traceback (most recent call last):
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context
    self.dialect.do_execute(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: taxon

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

Traceback (most recent call last):
  File "/home/andrewt/.local/bin/naturtag", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/andrewt/.local/lib/python3.10/site-packages/naturtag/cli.py", line 179, in tag
    metadata_list = list(tag_images(image_paths, observation, taxon))
  File "/home/andrewt/.local/lib/python3.10/site-packages/naturtag/metadata/inat_metadata.py", line 57, in tag_images
    inat_metadata = get_inat_metadata(
  File "/home/andrewt/.local/lib/python3.10/site-packages/naturtag/metadata/inat_metadata.py", line 101, in get_inat_metadata
    taxon = INAT_CLIENT.taxa(taxon_id, refresh=True)
  File "/home/andrewt/.local/lib/python3.10/site-packages/pyinaturalist/controllers/taxon_controller.py", line 17, in __call__
    return self.from_ids(taxon_id, **kwargs).one()
  File "/home/andrewt/.local/lib/python3.10/site-packages/naturtag/client.py", line 80, in from_ids
    save_taxa(results)
  File "/home/andrewt/.local/lib/python3.10/site-packages/pyinaturalist_convert/db.py", line 176, in save_taxa
    session.merge(DbTaxon.from_model(taxon))
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3036, in merge
    return self._merge(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3116, in _merge
    merged = self.get(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2848, in get
    return self._get_impl(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2955, in _get_impl
    return db_load_fn(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/orm/loading.py", line 530, in load_on_pk_identity
    session.execute(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1714, in execute
    result = conn._execute_20(statement, params or {}, execution_options)
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1705, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 333, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1572, in _execute_clauseelement
    ret = self._execute_context(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1943, in _execute_context
    self._handle_dbapi_exception(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2124, in _handle_dbapi_exception
    util.raise_(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
    raise exception
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context
    self.dialect.do_execute(
  File "/home/andrewt/.local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: taxon
[SQL: SELECT taxon.id AS taxon_id, taxon.active AS taxon_active, taxon.ancestor_ids AS taxon_ancestor_ids, taxon.child_ids AS taxon_child_ids, taxon.iconic_taxon_id AS taxon_iconic_taxon_id, taxon.leaf_taxa_count AS taxon_leaf_taxa_count, taxon.observations_count AS taxon_observations_count, taxon.name AS taxon_name, taxon.parent_id AS taxon_parent_id, taxon.partial AS taxon_partial, taxon.photo_urls AS taxon_photo_urls, taxon.preferred_common_name AS taxon_preferred_common_name, taxon.rank AS taxon_rank 
FROM taxon 
WHERE taxon.id = ?]
[parameters: (10227,)]
(Background on this error at: https://sqlalche.me/e/14/e3q8)
JWCook commented 1 year ago

Thanks for the bug report. That database is supposed to be set up when you launch the desktop app for the first time, but I haven't yet added something equivalent for the CLI.

Meanwhile, you can either run this from the command line:

python -c "from naturtag.settings import *; setup(Settings.read())"

Or install the desktop app (downloads here, and instructions here) and launch it once.

JWCook commented 1 year ago

Did this fix the issue for you?

I just remembered another option: this command will set up the database as well (although its main purpose is setting up shell tab-completion):

naturtag --install all
andrew-taylor commented 1 year ago

Apologies for slow reply - yes it ddi fix issue for me.