Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flights relation (and model) missing #158

Open
matburnham opened this issue Jul 3, 2022 · 1 comment
Open

flights relation (and model) missing #158

matburnham opened this issue Jul 3, 2022 · 1 comment

Comments

@matburnham
Copy link

Trying to extract flights for today causes an exception:

(ogn-python) mat@devbox:~/dev/ogn-python$ flask flights create 2022-07-03 2022-07-03 0
2022-07-03:   0%|                                                                     | 0/1 [00:14<?, ?it/s]
Traceback (most recent call last):
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1819, in _execute_context
    self.dialect.do_execute(
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.UndefinedTable: relation "flights" does not exist
LINE 2:         INSERT INTO flights(date, sender_id, flight_type, mu...
                            ^


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

Traceback (most recent call last):
  File "/home/mat/.virtualenvs/ogn-python/bin/flask", line 8, in <module>
    sys.exit(main())
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/flask/cli.py", line 990, in main
    cli.main(args=sys.argv[1:])
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/flask/cli.py", line 596, in main
    return super().main(*args, **kwargs)
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/flask/cli.py", line 440, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/mat/dev/ogn-python/app/commands/flights.py", line 28, in create
    result = compute_flights(date=single_date, flight_type=flight_type)
  File "/home/mat/dev/ogn-python/app/collect/flights.py", line 67, in compute_flights
    db.session.execute(query)
  File "<string>", line 2, in execute
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1712, in execute
    result = conn._execute_20(statement, params or {}, execution_options)
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1631, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 332, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1498, in _execute_clauseelement
    ret = self._execute_context(
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1862, in _execute_context
    self._handle_dbapi_exception(
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2043, in _handle_dbapi_exception
    util.raise_(
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
    raise exception
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1819, in _execute_context
    self.dialect.do_execute(
  File "/home/mat/.virtualenvs/ogn-python/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "flights" does not exist
LINE 2:         INSERT INTO flights(date, sender_id, flight_type, mu...
                            ^

So flights relation is missing. There's no flights.py in app/model. It looks like `flights2d.py' was removed in a18e6ae. I could try and re-create an appropriate table, but is this simply a file not committed to git?

@matburnham
Copy link
Author

Looks like something the following should work, based on INSERT INTO flights(date, sender_id, flight_type, multilinestring, simple_multilinestring)

from geoalchemy2.types import Geometry

from app import db

class Flight(db.Model):
    __tablename__ = "flights"

    date = db.Column(db.Date, primary_key=True)

    flight_type = db.Column(db.SmallInteger, primary_key=True)

    multilinestring = db.Column("multilinestring", Geometry("MULTILINESTRING", srid=4326))
    simple_multilinestring = db.Column("simple_multilinestring", Geometry("MULTILINESTRING", srid=4326))  # this is the path simplified with ST_Simplify(path, 0.0001)

    # Relations
    sender_id = db.Column(db.Integer, db.ForeignKey("senders.id", ondelete="CASCADE"), index=True)
    sender = db.relationship("Sender", foreign_keys=[sender_id], backref=db.backref("flights"))

    def __repr__(self):
        return "<Flight %s: %s,%s>" % (self.date, self.path_wkt, self.path_simple_wkt)


db.Index("ix_flights_date_sender_id", Flight.date, Flight.sender_id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant