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

A problem when I insert the root #82

Open
hanjie-chen opened this issue May 19, 2023 · 8 comments
Open

A problem when I insert the root #82

hanjie-chen opened this issue May 19, 2023 · 8 comments

Comments

@hanjie-chen
Copy link

hanjie-chen commented May 19, 2023

when I try to insert the root node in flask shell, there is something wrong happened

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/scoping.py", line 553, in commit
    return self._proxied.commit()
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1903, in commit
    trans.commit(_to_root=True)
  File "<string>", line 2, in commit
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/state_changes.py", line 137, in _go
    ret_value = fn(self, *arg, **kw)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1218, in commit
    self._prepare_impl()
  File "<string>", line 2, in _prepare_impl
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/state_changes.py", line 137, in _go
    ret_value = fn(self, *arg, **kw)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1193, in _prepare_impl
    self.session.flush()
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 4155, in flush
    self._flush(objects)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 4292, in _flush
    transaction.rollback(_capture_exception=True)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 147, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 4252, in _flush
    flush_context.execute()
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 467, in execute
    rec.execute(self)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 644, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 54, in save_obj
    save_obj(base_mapper, [state], uowtransaction, single=True)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 60, in save_obj
    for (
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 233, in _organize_states_for_save
    mapper.dispatch.before_insert(mapper, connection, state)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/event/attr.py", line 487, in __call__
    fn(*args, **kw)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/orm/events.py", line 889, in wrap
    fn(*arg, **kw)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy_mptt/events.py", line 574, in before_insert
    mptt_before_insert(mapper, connection, instance)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy_mptt/events.py", line 96, in mptt_before_insert
    select(
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/sql/_selectable_constructors.py", line 493, in select
    return Select(*entities)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/sql/selectable.py", line 5161, in __init__
    self._raw_columns = [
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/sql/selectable.py", line 5162, in <listcomp>
    coercions.expect(
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/sql/coercions.py", line 413, in expect
    resolved = impl._literal_coercion(
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/sql/coercions.py", line 652, in _literal_coercion
    self._raise_for_expected(element, argname)
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/sql/coercions.py", line 1143, in _raise_for_expected
    return super()._raise_for_expected(
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/sql/coercions.py", line 711, in _raise_for_expected
    super()._raise_for_expected(
  File "/Users/pingguo/opt/anaconda3/envs/Flask_Web/lib/python3.8/site-packages/sqlalchemy/sql/coercions.py", line 536, in _raise_for_expected
    raise exc.ArgumentError(msg, code=code) from err
sqlalchemy.exc.ArgumentError: Column expression, FROM clause, or other columns clause element expected, got [<sqlalchemy.sql.elements.BinaryExpression object at 0x7fee25170d90>]. Did you mean to say select(<sqlalchemy.sql.elements.BinaryExpression object at 0x7fee25170d90>)?

and my python code is here

from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy_mptt.mixins import BaseNestedSets

app = Flask(__name__)
url = 'sqlite:////' + os.path.join(app.root_path, 'data.db')
app.config['SQLALCHEMY_DATABASE_URI'] = url
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False 

db = SQLAlchemy(app)

class Category(db.Model, BaseNestedSets):
    __tablename__ = 'category'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)

    def __repr__(self):
        return '<Category {}>'.format(self.name)

and my python package is here
截屏2023-05-19 20 44 22
I can't figure out where is problem is, did that because the version of Flask-SQLAlchemy?

@EchoShoot
Copy link

EchoShoot commented Jun 8, 2023

i have the same problem, it's cause by sqlalchemy version is too high, you can follow this way
pip install sqlalchemy~=1.4.48

@corentinclichy
Copy link

hey,
I have the same issue.
Do you know if the issue will be fixed ?
Or is there another maintained library that support latest version of SQL Alchemy.
Thanks a lot.

@EchoShoot
Copy link

EchoShoot commented Aug 19, 2023

the code last update time is 2019, It's been a long time since no one has been maintaining it, there is no way to solve this problem

@corentinclichy
Copy link

Yes, but I saw there is a pr for that still waiting for validation

@corentinclichy
Copy link

Do you know if there is other maintained lib providing tree structure management ?

@tszyan
Copy link

tszyan commented Aug 23, 2023

@corentinclichy , if you want to use pr just install sqlalchemy_mptt from pr's branch:
https://github.com/lowatt/sqlalchemy_mptt/tree/sqlalchemy

In requirements.txt it will look like:
sqlalchemy_mptt @ git+https://github.com/lowatt/sqlalchemy_mptt@sqlalchemy

@corentinclichy
Copy link

corentinclichy commented Aug 28, 2023

@tszyan Are you sure that its ok to do that ? seems pretty risky to take deps from a pr IMO

Do you know other lib that provides same feature for sqlalchemy ?

@evgenybf
Copy link

@corentinclichy you can always create your fork and apply the changes from the pr in your fork. The library doesn't seem too complex to maintain it in a personal repo.

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

5 participants