Anonymous
Again, thanks for everything/personal support, you’re doing great work.
Robert
Hi guys, Not sure this is a Pony or a Flask question, but I'll try here. I am trying to build a login-function with Pony for storing users, but get some very strange behaviour, which I suspect is related to threading some how, but not sure. I have the code found here: https://pastebin.com/LbE47zdK, where I can store the database on disk (line 25) or in memory (line 24). Lines 55-63 are used to create some dummy users for development purpose. When running thing with Flask, storing the database on disk works as expected, but when storing the database in memory throws an exception: pony.orm.dbapiprovider.OperationalError: no such table: User. Any ideas? Thanks.
Alexander
Hi! By default in-memory database cannot work with threads, as each thread creates a new in-memory database. There is a way to fix it, I need to look at it #todo
Alexander
Right now use file database if you work with threads
Robert
Thanks
Konstantin
Hi! Can you help me? Is there any description of the testing procedure? Configuration file format to run tests and so on?
Alexander
You mean PonyORM tests?
Alexander
Or application tests for program that uses PonyORM?
Konstantin
O, sorry that without clarification PonyORM tests
Konstantin
I see, for example, that _load_env() func uses settings_filename for setting up db Can I find somewhere file format?
Alexander
The content of file may look like this: settings = dict( provider='sqlite', filename=':memory:' # provider='postgres', user='pony', password='pony', host='localhost', port='5432', database='pony' # provider='cockroach', user='root', host='localhost', port=26257, sslmode='disable', database='test' )
Alexander
Each test run performed for a single database provider
Konstantin
I got it Thank you!
Anonymous
how can i store objects which consists of List[Sequence[str]]? e.g [("a", "b"), ("c", "d")] or [["a", "b"], ["c", "d"]] if there's a restriction i can only use List[List[str]] instead of tuples/lists/sets etc.
Anonymous
or even [{"a": "b"}, {"c": "d"}]
Alexander
In JSON column you can store arbitrary valid JSON
Anonymous
Ah, thanks. i didn't know about pony.orm.Json
Alexander
https://docs.ponyorm.org/json.html
Karsten
Hello, I'm just getting started with Pony. Can I also determine the names of the columns from a query. I've only got one list back so far. for example : ['test_1', '01.01.2021 ', '12: 53'] Better legibility would be good for further processing. For example: {'name': 'test_1', 'year': '01.01.2021 ', 'time': '12: 53 '} SQLAlchemy offers this possibility: var = (rows [0]) ['time'] Greetings
Alexander
Can you show an example of your query?
Karsten
Yes. part of the 'get_password' method : result = select((u.password, u.is_admin, u.initials) for u in User if u.user_name == name) if result.count() > 0: print(result.count()) for row in result: return row else: return [] and the next process : row = self._get_password(user_name) print(len(row)) if (len(row) > 0) and (row[0] == password): self.__is_authorized = True self.__net = net self.__user_name = user_name self.__is_admin = bool(row[1]) self.__initials = str(row[2]) self.login_changed(self, LoginChangedEventArgs(is_authorized=True, net=net))
Alexander
1) what you named result is actually a query, which wasn't evaluated yet. The actual query evaluation happens two times, when you call result.count() and when you do for row in result, and Python calculates iter(result). 2) if you actually get a result, it is a QueryResult object which has additional attributes for column names and types: query = select((u.password, u.is_admin, u.initials) for u in User if u.user_name == name) result = query.fetch() # or query[:] if len(result) > 0: print(len(result)) print(result._col_names) # will print ['u.password', 'u.is_admin', 'u.initials'] for row in result: ... 3) Usually it is more convenient to query an entire object: query = select(u for u in User if u.user_name == name) result = query.fetch() # or query[:] if len(result) > 0: print(len(result)) print(result._col_names) # will print ['id', 'user_name', 'password', 'is_admin', 'initials'] for u in result: print(u.id, u.user_name, u.is_admin)
Karsten
Oh ! Many Thanks ! So is this code possible then? var = (row[0])['password'] I will try it at some point.
Alexander
If you do select(u for u in User if u.user_name == name) or User.select(lambda u: u.user_name == name) Then you can do for u in result: print(u.password) print(getattr(u, 'password'))
Karsten
Aha, so the calling method needs to know that 'u' was used in the query. I try it. Thanks
Karsten
@Alexander: When I pass result to the calling method, I get an error message ready for print (u.password). :( Here is the current code: @db_session def _get_password(self, name: str) : ret_val = dict() result = select((u.password, u.is_admin, u.initials) for u in User if u.user_name == name) result.fetch() if result.count() > 0: print(result.count()) return result else: return [] def log_on(self, net: str, user_name: str, password: str) -> None: result = self._get_password(user_name) for u in result: print(u.password) if (len(u) > 0) and (u.password == password): self.__is_authorized = True self.__net = net self.__user_name = user_name self.__is_admin = bool(u.is_admin) self.__initials = str(u.initials) self.login_changed(self, LoginChangedEventArgs(is_authorized=True, net=net)) else: self._reset() self.login_changed(self, LoginChangedEventArgs()) .....
Alexander
In my example I select u object itself, not (u.password, u.is_admin, u.initials)
Karsten
You're right, now it works for me too. But what if I don't want to select everything with large tables? Thanks
Alexander
Usually, it is not too slow to select excess columns, as they are stored on the same page inside the database. It is much worse to select excess rows. But if some column is especially large, you can add lazy=True option to its description, and it will not be loaded until explicitly requested.
Karsten
Thank you for the very quick support!
Anonymous
By the way, Alexander, did you make those Docs and Diagrams Editor by yourself or did you use a template?
Alexander
It was developed mainly by @alexey115
Alexander
It was developed from scratch
Anonymous
Oh :D I want to ‘migrate’ this thing, like to use it on my own domain. (e.g editor.domain.com). Is it possible/open source? If so, what license?
Anonymous
It was developed from scratch
WoW 🤩 That’s really cool and professional
Alexander
Sorry, Diagram Editor is not open source
Anonymous
Ah :(
Anonymous
But well, the most of the code is JS, isn’t it?
Alexander
yes
Anonymous
Ah, nice
Alexander
Originally it was based on KnockoutJS, and then it was rewritten to use MobX
Alexander
self-written SVG-manipulation code over MobX
El Mojo
Oki nice job! why did you make this choice?
Alexander
Because it is hard to sell licenses on Python libraries, so PonyORM was released under a free license, and Diagram Editor was made as a commercial product.
El Mojo
Because it is hard to sell licenses on Python libraries, so PonyORM was released under a free license, and Diagram Editor was made as a commercial product.
No, I was talking about the svg choice, why not a js library that makes most of the diagramming job, like butterfly, d3, antv, etc.?
Konstantin
maybe it can help against spammers @shieldy_bot
Alexander
The bot needs to be an admin to kick other users. Some time ago we lost the ability to make new admins in this group. We can create another channel, but probably it is better to keep it as is, the number of spammers is not too big.
Konstantin
Speaking about ponyorm tests I try to run sql_tests.py with command PYTHONPATH=$(pwd) python pony/orm/tests/sql_tests.py (which is same as PYTHONPATH=$(pwd) coverage run -a --source pony.orm.dbapiprovider,pony.orm.dbschema,pony.orm.decompiling,pony.orm.core,pony.orm.sqlbuilding,pony.orm.sqltranslation --branch sql_tests.py) And I got an error: pony.orm.dbapiprovider.OperationalError: no such table: CartItem Does sql_tests.py have to create this table? Or where i can find pre-sql-testing script? Can you help me? UPD: error raise during execution File "estore.py", line 59, in <module> db.generate_mapping(create_tables=True)
Konstantin
Thank you I already find this problem in this exactly file and fixed it by myself Then, now i'm going to apply your changes and recreate pull request
Konstantin
Done, Please, check pull request. I hope it will be useful
Alexander
Thank you for the PR! I'm overloaded with work today, so cannot look at it right now, let's discuss it tomorrow
Alexander
I have, but the channel was created from another account (which is now deleted due to inactivity), and when it granted admin rights to other accounts it mistakenly did it without "grant permissions", so now it is impossible to create new admins.
Konstantin
Hm, Maybe there is some chance to write a request to support and return these 'superuser' rights back Loks like it's possible
Anonymous
btw @metaprogrammer the 1st section seems broken, unlike the others
Anonymous
even long sections are ok
Alexander
Thank you for reporting!
Anonymous
you're welcome, Thanks for awesome project!
Alexey
No, I was talking about the svg choice, why not a js library that makes most of the diagramming job, like butterfly, d3, antv, etc.?
Thanks for the compliment! It was pretty interesting to implement from scratch, that’s why we experimented with canvas and svg and went forward with SVG. D3 is also good choice, but for us, SVG did the job
Anonymous
i get ValueError: Attribute Car.color cannot be set to None where Car.color is Optional(str) and i create the instance so: Car( ... color=COLOR ...) [COLOR is either None or a color-as-string]
Volbil
nullable=True
Anonymous
ah ok, Thanks. so what's the point of Optional? isn't is the same as Required with nullable?
Alexander
https://docs.ponyorm.org/api_reference.html?highlight=nullable#optional-string-attributes
Anonymous
Thanks
Volbil
Anonymous
if i specify nullable=True, does it take more resources/time to process?
Volbil
I don't think so
Volbil
Should be same in terms of speed
Anonymous
pony.orm.core.TransactionIntegrityError: Object Car[new:1] cannot be stored in the database. IntegrityError: NOT NULL constraint failed: Car.color :C when i set nullable=True
Matthew
remove the not null constraint in the database
Anonymous
Alexander
If you have an empty database, you can do (after db.generate_mapping): db.drop_all_tables(with_all_data=True) db.create_tables()
Anonymous
will it delete the DB even if there is an exist database?
Alexander
it will delete all content from the db
Alexander
And recreates the tables
Anonymous
Oh ok. Thanks!