Code Monkey home page Code Monkey logo

Comments (9)

bevanj avatar bevanj commented on June 20, 2024

I am also experiencing this issue. Sorry I don't have anything more to add (Postgresql 9.3)

from dataset.

pudo avatar pudo commented on June 20, 2024

Fixed in a95c7be

from dataset.

smnorris avatar smnorris commented on June 20, 2024

Thanks!

from dataset.

jensfinnas avatar jensfinnas commented on June 20, 2024

I'm still experiencing the same issue here.

>>> db = dataset.connect(os.environ["DB_URL"], schema="1")
>>> table = db['person']
>>> print(table.columns)
['id']
>>> table.insert(dict(name='John Doe', age=46))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/dataset/persistence/table.py", line 72, in insert
    self._ensure_columns(row, types=types)
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/dataset/persistence/table.py", line 214, in _ensure_columns
    self.create_column(column, _type)
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/dataset/persistence/table.py", line 241, in create_column
    Column(name, type)
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/alembic/operations.py", line 595, in add_column
    schema=schema
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/alembic/ddl/impl.py", line 176, in add_column
    self._exec(base.AddColumn(table_name, column, schema=schema))
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/alembic/ddl/impl.py", line 122, in _exec
    return conn.execute(construct, *multiparams, **params)
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1989, in execute
    return connection.execute(statement, *multiparams, **params)
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 914, in execute
    return meth(self, multiparams, params)
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
    return connection._execute_ddl(self, multiparams, params)
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 968, in _execute_ddl
    compiled
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
    context)
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
    exc_info
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
    context)
  File "/Users/Jens/Dropbox/journalism++/jsurveillance/Scraper/env/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation "person" does not exist
 [SQL: 'ALTER TABLE person ADD COLUMN age INTEGER']

from dataset.

smnorris avatar smnorris commented on June 20, 2024

Yes, me too. I'm going to try and make a test for this.

from dataset.

smnorris avatar smnorris commented on June 20, 2024

I can fix this one issue by specifying the schema in create_column of table.py

    def create_column(self, name, type):
        """
        Explicitely create a new column ``name`` of a specified type.
        ``type`` must be a `SQLAlchemy column type <http://docs.sqlalchemy.org/en/rel_0_8/core/types.html>`_.
        ::

            table.create_column('created_at', sqlalchemy.DateTime)
        """
        self._check_dropped()
        self.database._acquire()

        try:
            if normalize_column_name(name) not in self._normalized_columns:
                self.database.op.add_column(
                    self.table.name,
                    Column(name, type),
                    self.table.schema
                )
                self.table = self.database.update_table(self.table.name)
        finally:
            self.database._release()

However, running the complete test_persistence.py when connected to a specific postgres schema has more problems.

======================================================================
ERROR: test_query (test.test_persistence_pg.DatabaseTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_persistence_pg.py", line 135, in test_query
    r = self.db.query('SELECT COUNT(*) AS num FROM weather').next()
  File "dataset/persistence/database.py", line 294, in query
    return ResultIter(self.executable.execute(query, **kw),
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1989, in execute
    return connection.execute(statement, *multiparams, **params)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 914, in execute
    return meth(self, multiparams, params)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
    context)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
    exc_info
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
    context)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
ProgrammingError: (psycopg2.ProgrammingError) relation "weather" does not exist
LINE 1: SELECT COUNT(*) AS num FROM weather
                                    ^
 [SQL: 'SELECT COUNT(*) AS num FROM weather']

Sending a plain query text string fails unless table names in the string are schema qualified. This makes sense and https://stackoverflow.com/questions/9298296/sqlalchemy-support-of-postgres-schemas has some ideas on how to deal with it. I tried the to set the path via event listener but the test seems to be creating too many connections and postgres complains.

Also, the test has failures like this when connected to postgres

======================================================================
ERROR: test_find_one (test.test_persistence_pg.RowTypeTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_persistence_pg.py", line 372, in test_find_one
    assert d.temperature == -10, d
AttributeError: 'OrderedDict' object has no attribute 'temperature'

Maybe just a setting somewhere in sqlalchemy or psycopg2 to get the query results accessible as properties but I'm leaving this for now.

from dataset.

jvidin avatar jvidin commented on June 20, 2024

Hi all , wondering if you can help, i can't find how to specify the schema to make my inserts, im using postgres. Thank you for all the great work with dataset

from dataset.

pudo avatar pudo commented on June 20, 2024

@jvidin I've incorporated the fix suggested by @smnorris - can you check that fixes the issue for you, as well?

from dataset.

pudo avatar pudo commented on June 20, 2024

Fixed.

from dataset.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.