Hi

I feel I have exhausted all the usual options in finding a solution
for this problem.

I'm using Python 2.5.5, SQLAlchemy 0.4.6, and Elixir 0.5.2. I'm really
not sure how much code I should include for this to make any sense to
others.

------------------------------------------------------------------------------------------------------------------------------------------------------------------
The actual traceback is as follows:

ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (30, 0))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call
last)

C:\Users\User\My iFolder\My Development\Python\TurboGears\DMS-Test
\dmstest\model.py in <module>()
----> 1
      2
      3
      4
      5

C:\Users\User\My iFolder\My Development\Python\TurboGears\DMS-Test
\dmstest\model.py in register(cls, person, ref, versio
n, file_name, reg_date, write)
    564                     names.append(record['author-%s' % a])
    565                 else:
--> 566                     doc.authors.append(author)
    567                 a += 1
    568

c:\VirtualEnvs\tg1env\lib\site-packages\sqlalchemy-0.4.6-py2.5.egg
\sqlalchemy\orm\collections.pyc in append(self, item,
_sa_initiator)
    919                 if executor:
    920
executor.attr.fire_append_event(executor.owner_state,
--> 921                                                     item,
_sa_initiator)
    922             fn(self, item)
    923         _tidy(append)

c:\VirtualEnvs\tg1env\lib\site-packages\sqlalchemy-0.4.6-py2.5.egg
\sqlalchemy\orm\attributes.pyc in fire_append_event(se
lf, state, value, initiator)
    509
    510         if self.trackparent and value is not None:
--> 511             self.sethasparent(value._state, True)
    512         instance = state.obj()
    513         for ext in self.extensions:

AttributeError: 'list' object has no attribute '_state'
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
My Document class in model is:

class Document(Entity):
    REF_CODE = u'ITS'

    ref_code = Field(Unicode(3), nullable=False, default=REF_CODE)
    ref_num = Field(Unicode(4), nullable=False)
    ref_lang = Field(Unicode(1), nullable=False, default='')
    ref_ext = Field(Unicode(2), nullable=False, default='')
    title = Field(Unicode(130), nullable=False)
    synopsis = Field(Unicode, default=None)
    visibility_id = Field(Integer, nullable=False, default=3)
    format_id = Field(Integer, nullable=False, default=3)
    type_id = Field(Integer, nullable=False)
    section_id = Field(Integer, nullable=False)
    subsection_id = Field(Integer, nullable=False, default=0)
    category_id = Field(Integer, nullable=False)
    _reg_date = Field(Date, nullable=False, default=date.today)
    dr_and_bc_id = Field(Integer, nullable=False, default=0)
    notes = Field(String(100), default=None)
    owner = ManyToOne('Person', required=True)
    project = ManyToOne('Project')
    versions = OneToMany('Version', order_by=['_reg_date'])
    statuses = OneToMany('DocumentStatus', inverse='doc',
order_by=['id'])
    authors = ManyToMany('Person', tablename='document_author',
                         order_by=['surname', 'initials'])
    related_docs = ManyToMany('Document',
tablename='document_related_doc', inverse='related_to',
                              order_by=['ref_code', 'ref_num',
'ref_lang', 'ref_ext'])
    related_to = ManyToMany('Document',
tablename='document_related_doc', inverse='related_docs',
                              order_by=['ref_code', 'ref_num',
'ref_lang', 'ref_ext'])

    using_options(
        tablename='document',
        order_by=['ref_code', 'ref_num', 'ref_lang', 'ref_ext']
    )
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
My Document.register() class method:

    @classmethod
    def register(cls, person=None, ref=None, version=None,
file_name='CFG1039', reg_date=None, write=False):
        """
        Registers new document from parsed XML record saved in file.

        Usage: register(person=None, ref=None, version=None,
file_name='CFG1039', reg_date=None, write=False)

        Returns Document or None.
        """
        if _is_logged_in():
            log_input("Document.register(person=%s, ref='%s', version=
%s, file_name='%s', reg_date=%s, write=%s)" \
                      % (person, ref, version, file_name, reg_date,
write))
            record = parse_record(file_name)
            if record:
                if ref:
                    doc_ref = u'%s' % ref
                else:
                    max_ref = Document.query.filter(Document.ref_num <
u'9000').max(Document.ref_num)
                    new_ref = str(int(max_ref) + 1)
                    doc_ref = u'ITS' + new_ref +
choices.find_value(record['language'], choices.LANGUAGE_CHOICES) + ' '

                reg_date = resolve_date(reg_date)
                log_input("-> Document(ref='%s', title='%s',
synopsis='%s', reg_date=%s, type='%s', section='%s', visibility='%s',
format='%s', category='%s')" \
                          % (doc_ref, record['title'],
record['synopsis'], reg_date, \
                             record['type'], record['section'], \
                             record['visibility'], record['format'],
record['category']))
                doc = Document(ref=doc_ref, title=record['title'],
synopsis=record['synopsis'], reg_date=reg_date,
                    type=record['type'], section=record['section'], #
Currently to be provided by hand
                    visibility=record['visibility'],
format=record['format'], category=record['category'])
                if 'subsection' in record:
                    doc.subsection = record['subsection']
                if 'notes' in record:
                    doc.notes = record['notes']
                else:
                    doc.notes = u''
                log_input("Added with separate code: subsection=%s and
notes='%s'" \
                          % (doc.subsection, doc.notes), doc)
            else:
                out = 'Document not registered - problem with parsing
record'
                print out
                log_output(out)
                return None

            names = []  # List of any unknown names

            a = 1   # Author counter, to cater for multiple authors
            while 'author-%s' % a in record:
                author = Person.get(record['author-%s' % a])
                if not author and record['author-%s' % a] not in
names:
                    names.append(record['author-%s' % a])
                else:
                    doc.authors.append(author) # Offending code -
simply appending to list <---------------------------------------
                a += 1

            doc.owner = Person.get(record['owner'])
            if not doc.owner and record['owner'] not in names:
                names.append(record['owner'])

            if person == None:
                if current_user:
                    person = current_user
            else:
                if person.__class__.__name__ != 'Person':
                    name = u'%s' % person
                    person = Person.get(name)
            if not person and name not in names:
                names.append(name)

            if doc.authors and doc.owner and person and not names:
                log_input("-> Version._create(doc=%s, number='%s',
reg_date=%s)" \
                          % (doc, version, reg_date))
                version = Version._create(doc=doc, number=version,
reg_date=reg_date)
                if version:
                    doc.version = version
                    log_input("-> DocumentStatus(status='Checked in',
person=%s, date=%s)" \
                              % (person, reg_date), doc)
                    doc.status = DocumentStatus(status=u'Checked in',
person=person, date=reg_date)
                    doc.flush()
                    out = '\nDocument "%s-%s" registered by "%s"' % \
                        (doc.ref, doc.version.number,
doc.status.person.short_name)
                    if write:
                        doc.write()
                        doc.version.write()

                    # Send appropriate message
                    activity = 'Document Registration'
                    message = 'This document has been registered by
%s' % person.long_name
                    send_doc_message(activity, message, doc, person)

                    print out
                    log_output(out)
                    return doc
                else:
                    out = '\nDocument "%s-%s" not registered - problem
creating version' % \
                        (doc.ref, doc.version.number)
                    print out
                    log_output(out)
                    return None
            else:
                out = '\nThe following names do not exist: '
                for n in names[:-1]:
                    out += '%s, ' % n
                out += '%s!' % names[-1]
                print out
                log_output(out)
                return None
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Usage:

d = Document.register(person='van der walt')
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
This method has been working for some years. Changes I recently made
have nothing to do with this problem. If I run the
"doc.authors.append(author)" manually, it works (as it should)! I have
a legal Person object for author. Authors is a legally defined
relationship on Document.

Google delivered one post from 2007, which I couldn't really make
"work" for me.

Assitance will be greatly appreciated. (Should more info/code be
required, I'll gladly provide it.

Regards

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to