Re: [sqlalchemy] Re: Questions about session

2010-06-28 Thread Conor
On 06/10/2010 04:32 PM, Az wrote: Let me take a guess: class Supervisor(object): def __init__(self, ee_id, name, original_quota, loading_limit): self.ee_id = ee_id self.name = name self.original_quota = original_quota

Re: [sqlalchemy] Re: Questions about session

2010-06-28 Thread Conor
On 06/10/2010 12:33 PM, Az wrote: The pprintout was: {type 'collections.defaultdict': 156, type 'bool': 2, type 'float': 1, type 'int': 538, type 'list': 1130, type 'dict': 867, type 'NoneType': 1, type 'set': 932, type 'str': 577, type 'tuple': 1717, type 'type': 5, class

[sqlalchemy] Re: Questions about session

2010-06-12 Thread Az
Hi Conor, Many apologies for being pushy but since I'm pretty much in the processing of finishing up my code (due in two days), I wonder if you could just take a look at the last three posts of mine---these constitute the final hurdle and I'll be done :) Cheers, Az On Jun 9, 9:46 pm, Conor

[sqlalchemy] Re: Questions about session

2010-06-10 Thread Az
The pprintout was: {type 'collections.defaultdict': 156, type 'bool': 2, type 'float': 1, type 'int': 538, type 'list': 1130, type 'dict': 867, type 'NoneType': 1, type 'set': 932, type 'str': 577, type 'tuple': 1717, type 'type': 5, class 'sqlalchemy.util.symbol': 1, class

[sqlalchemy] Re: Questions about session

2010-06-10 Thread Az
So I laid them out like this: class Run(Base): # For autoincrementing run IDs # Allows addition of more information to a run __tablename__ = 'run' id = Column(Integer, primary_key=True) timestamp = Column(DateTime, nullable=False) # comment = Column(UnicodeText(100),

[sqlalchemy] Re: Questions about session

2010-06-10 Thread Az
Let me take a guess: class Supervisor(object): def __init__(self, ee_id, name, original_quota, loading_limit): self.ee_id = ee_id self.name = name self.original_quota = original_quota self.loading_limit = loading_limit

Re: [sqlalchemy] Re: Questions about session

2010-06-09 Thread Conor
On 06/08/2010 10:54 PM, Az wrote: memo = {} copied_students = copy.deepcopy(students, memo) copied_supervisors = copy.deepcopy(supervisors, memo) copied_projects = copy.deepcopy(projects, memo) After you do this, memo will contain a record of all copied objects. You should examine

Re: [sqlalchemy] Re: Questions about session

2010-06-09 Thread Conor
On 06/09/2010 12:44 AM, Az wrote: Traceback (most recent call last): File Main.py, line 39, in module MCS.monteCarloBasic(trials) File //MonteCarloSimulation.py, line 163, in monteCarloBasic session.merge(temp_alloc) File

[sqlalchemy] Re: Questions about session

2010-06-09 Thread Az
Expected: students, supervisors, projects, dictionaries of said objects, and other attribute values (strings, ints, lists, etc.). Unexpected: anything else, especially sessions, InstanceState objects, or other ORM support objects. Actually got some stuff like the following (copy-pasting bits

Re: [sqlalchemy] Re: Questions about session

2010-06-09 Thread Conor
On 06/09/2010 02:45 PM, Az wrote: Expected: students, supervisors, projects, dictionaries of said objects, and other attribute values (strings, ints, lists, etc.). Unexpected: anything else, especially sessions, InstanceState objects, or other ORM support objects. Actually got some

Re: [sqlalchemy] Re: Questions about session

2010-06-08 Thread Conor
On 06/07/2010 07:27 PM, Az wrote: By default, deepcopy will make one copy of everything in the object graph reachable by the object you feed it. The scary part is that, unless you also pass in a /memo/ argument to each call to deepcopy, it will copy the entire graph /every single call/. So if

[sqlalchemy] Re: Questions about session

2010-06-08 Thread Az
memo = {} copied_students = copy.deepcopy(students, memo) copied_supervisors = copy.deepcopy(supervisors, memo) copied_projects = copy.deepcopy(projects, memo) After you do this, memo will contain a record of all copied objects. You should examine memo.values() to see if it is copying more

[sqlalchemy] Re: Questions about session

2010-06-08 Thread Az
Also: Traceback (most recent call last): File Main.py, line 39, in module MCS.monteCarloBasic(trials) File /Users/Azfar/Dropbox/Final Year Project/SPAllocation/ MonteCarloSimulation.py, line 163, in monteCarloBasic session.merge(temp_alloc) File

[sqlalchemy] Re: Questions about session

2010-06-08 Thread Az
Traceback (most recent call last): File Main.py, line 39, in module MCS.monteCarloBasic(trials) File //MonteCarloSimulation.py, line 163, in monteCarloBasic session.merge(temp_alloc) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/

Re: [sqlalchemy] Re: Questions about session

2010-06-07 Thread Conor
On 06/06/2010 02:58 PM, Az wrote: Hi Conor, Basically I sat down and made some decisions and changes. I've created an actual copy of the Student class as in I've now got two classes, Student and StudentUnmapped. The Unmapped one has the same attributes as the mapped one, except for being...

[sqlalchemy] Re: Questions about session

2010-06-07 Thread Az
Sounds good. Just beware that deepcopy will try to make copies of all the objects referenced by your StudentUnmapped objects (assuming you didn't define __deepcopy__), so you may end up copying projects, supervisors, etc. Good point. I'm deepcopying my students, projects and supervisors

Re: [sqlalchemy] Re: Questions about session

2010-06-07 Thread Conor
On 06/07/2010 02:56 PM, Az wrote: Sounds good. Just beware that deepcopy will try to make copies of all the objects referenced by your StudentUnmapped objects (assuming you didn't define __deepcopy__), so you may end up copying projects, supervisors, etc. Good point. I'm deepcopying my

[sqlalchemy] Re: Questions about session

2010-06-07 Thread Az
By default, deepcopy will make one copy of everything in the object graph reachable by the object you feed it. The scary part is that, unless you also pass in a /memo/ argument to each call to deepcopy, it will copy the entire graph /every single call/. So if you deepcopy the students

[sqlalchemy] Re: Questions about session

2010-06-07 Thread Az
Additionally, before I tried out the create_db_record... However whenever I try to commit: #[§§0§] student_records = best_node for rec in student_records.itervalues(): MCS.session.add(rec) MCS.session.commit() I get:

[sqlalchemy] Re: Questions about session

2010-06-06 Thread Az
Hi Conor, Basically I sat down and made some decisions and changes. I've created an actual copy of the Student class as in I've now got two classes, Student and StudentUnmapped. The Unmapped one has the same attributes as the mapped one, except for being... well, unmapped. Now I can a) use

[sqlalchemy] Re: Questions about session

2010-06-05 Thread Az
Cheers! Creating a new instance of my mapped class and settings, manually. Gotcha. I think this will be an easier solution for me. Nah, I'm not in a web framework. Additional Q: +++ Currently, my database is being stored in memory and it's fine like that since a) my data isn't very expansive

Re: [sqlalchemy] Re: Questions about session

2010-06-05 Thread Conor
On 06/05/2010 08:06 PM, Az wrote: Cheers! Creating a new instance of my mapped class and settings, manually. Gotcha. I think this will be an easier solution for me. Nah, I'm not in a web framework. Additional Q: +++ Currently, my database is being stored in memory and it's fine like

[sqlalchemy] Re: Questions about session

2010-06-05 Thread Az
This will probably help: def addToTable(): Very simple SQLAlchemy function that populates the Student, Project and Supervisor tables. for student in students.itervalues(): session.add(student) session.flush() for project in

[sqlalchemy] Re: Questions about session

2010-06-05 Thread Az
Also adding a bit here: My Student (this one is mapped) class looks like this: class Student(object): def __init__(self, ee_id, name, stream_id, overall_proby): self.ee_id = ee_id self.name = name self.stream_id = stream_id

[sqlalchemy] Re: Questions about session

2010-06-04 Thread Az
Sorry, meant to reply to you Michael... ended up replying to myself! --- Firstly, apologies if I'm demanding too much but basically I'm quite a beginner at Python programming and this is for a University project, which is why I'm keen to get this done (due in a few days!). So I hope you won't

Re: [sqlalchemy] Re: Questions about session

2010-06-04 Thread Conor
On 06/03/2010 02:33 PM, Az wrote: Firstly, apologies if I'm demanding too much but basically I'm quite a beginner at Python programming and this is for a University project, which is why I'm keen to get this done (due in a few days!). So I hope you won't mind me asking some questions that may

[sqlalchemy] Re: Questions about session

2010-06-03 Thread Az
Owning session has been closed? Can I still use deepcopy if the session has not been closed? How can I stop it from closing the sessions? The problem is that if I change my shallow copied dictionary, the objects are changed. Basically, I'm trying to do this state change thing where I'll take a

Re: [sqlalchemy] Re: Questions about session

2010-06-03 Thread Michael Bayer
On Jun 3, 2010, at 1:58 PM, Az wrote: Owning session has been closed? Can I still use deepcopy if the session has not been closed? deepcopy has issues because SQLAlchemy places extra information on your objects, i.e. an _sa_instance_state attribute, that you dont want in your copy. You

[sqlalchemy] Re: Questions about session

2010-06-03 Thread Az
I think I get what you mean. In the mean time, another error popped up: Traceback (most recent call last): File Main.py, line 32, in module MCS.addToTable() File XXX/MonteCarloSimulation.py, line 138, in addToTable ### --- This function is described in the first post

[sqlalchemy] Re: Questions about session

2010-06-02 Thread Az
Also: I'm using [Python 2.6.5] and [SQLAlchemy 0.5.8] Previously I was just shallow copying my dictionaries, and there were no issues then with my simulations. My dictionaries contain objects such that my students dictionary is basically: students[stud_id] = Student(stud_id, name,