~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/engine/reflection.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2013-10-28 22:29:40 UTC
  • mfrom: (1.4.24)
  • Revision ID: package-import@ubuntu.com-20131028222940-wvyqffl4g617caun
Tags: 0.8.3-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
368
368
 
369
369
        # table attributes we might need.
370
370
        reflection_options = dict(
371
 
            (k, table.kwargs.get(k)) for k in dialect.reflection_options if k in table.kwargs)
 
371
            (k, table.kwargs.get(k))
 
372
            for k in dialect.reflection_options if k in table.kwargs)
372
373
 
373
374
        schema = table.schema
374
375
        table_name = table.name
394
395
 
395
396
        # columns
396
397
        found_table = False
 
398
        cols_by_orig_name = {}
 
399
 
397
400
        for col_d in self.get_columns(table_name, schema, **tblkw):
398
401
            found_table = True
 
402
            orig_name = col_d['name']
 
403
 
399
404
            table.dispatch.column_reflect(self, table, col_d)
400
405
 
401
406
            name = col_d['name']
433
438
                    sequence.increment = seq['increment']
434
439
                colargs.append(sequence)
435
440
 
436
 
            col = sa_schema.Column(name, coltype, *colargs, **col_kw)
 
441
            cols_by_orig_name[orig_name] = col = \
 
442
                        sa_schema.Column(name, coltype, *colargs, **col_kw)
 
443
 
437
444
            table.append_column(col)
438
445
 
439
446
        if not found_table:
443
450
        pk_cons = self.get_pk_constraint(table_name, schema, **tblkw)
444
451
        if pk_cons:
445
452
            pk_cols = [
446
 
                table.c[pk]
 
453
                cols_by_orig_name[pk]
447
454
                for pk in pk_cons['constrained_columns']
448
 
                if pk in table.c and pk not in exclude_columns
 
455
                if pk in cols_by_orig_name and pk not in exclude_columns
449
456
            ]
450
457
            pk_cols += [
451
458
                pk
463
470
        fkeys = self.get_foreign_keys(table_name, schema, **tblkw)
464
471
        for fkey_d in fkeys:
465
472
            conname = fkey_d['name']
466
 
            constrained_columns = fkey_d['constrained_columns']
 
473
            # look for columns by orig name in cols_by_orig_name,
 
474
            # but support columns that are in-Python only as fallback
 
475
            constrained_columns = [
 
476
                                    cols_by_orig_name[c].key
 
477
                                    if c in cols_by_orig_name else c
 
478
                                    for c in fkey_d['constrained_columns']
 
479
                                ]
467
480
            if exclude_columns and set(constrained_columns).intersection(
468
481
                                exclude_columns):
469
482
                continue
503
516
                    "Omitting %s KEY for (%s), key covers omitted columns." %
504
517
                    (flavor, ', '.join(columns)))
505
518
                continue
506
 
            sa_schema.Index(name, *[table.columns[c] for c in columns],
 
519
            # look for columns by orig name in cols_by_orig_name,
 
520
            # but support columns that are in-Python only as fallback
 
521
            sa_schema.Index(name, *[
 
522
                                cols_by_orig_name[c] if c in cols_by_orig_name
 
523
                                        else table.c[c]
 
524
                                for c in columns
 
525
                        ],
507
526
                         **dict(unique=unique))