Whole file
andialbrecht/sqlparse
The author described this change as “Fix issue with get_real_name returning incorrect name”. It counts as a record because the check below fails on the code as it stood at 19b9e6756 and passes on e07e09540, with nothing else changed between the two runs.
Projectandialbrecht/sqlparse
Fix saved2018-03-21
Sharing licenceBSD-3-Clause · LICENSE
Change size+4 −3
What the code was meant to do, written into the code itself as a save note
Fix issue with get_real_name returning incorrect name
The change
| 358 | 358 | """Returns the real name (object name) of this identifier.""" | |
| 359 | 359 | # a.b | |
| 360 | 360 | dot_idx, _ = self.token_next_by(m=(T.Punctuation, '.')) | |
| 361 | - | return self._get_first_name(dot_idx) | |
| 361 | + | return self._get_first_name(dot_idx, real_name=True) | |
| 362 | 362 | ||
| 363 | 363 | def get_parent_name(self): | |
| 364 | 364 | """Return name of the parent object if any. | |
| ⋯ | |||
| 369 | 369 | _, prev_ = self.token_prev(dot_idx) | |
| 370 | 370 | return remove_quotes(prev_.value) if prev_ is not None else None | |
| 371 | 371 | ||
| 372 | - | def _get_first_name(self, idx=None, reverse=False, keywords=False): | |
| 372 | + | def _get_first_name(self, idx=None, reverse=False, keywords=False, | |
| 373 | + | real_name=False): | |
| 373 | 374 | """Returns the name of the first token with a name""" | |
| 374 | 375 | ||
| 375 | 376 | tokens = self.tokens[idx:] if idx else self.tokens | |
| ⋯ | |||
| 383 | 384 | if token.ttype in types: | |
| 384 | 385 | return remove_quotes(token.value) | |
| 385 | 386 | elif isinstance(token, (Identifier, Function)): | |
| 386 | - | return token.get_name() | |
| 387 | + | return token.get_real_name() if real_name else token.get_name() | |
| 387 | 388 | ||
| 388 | 389 | ||
| 389 | 390 | class Statement(TokenList): | |
The check that tells the two apart
fail→pass·tests/test_parse.py::test_get_real_name
Check file tests/test_parse.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it19b9e6756c796752565950d89598ef8b46ca786d
Broken version dated2018-03-21
Modulesqlparse.sql
Units changedTokenList
Fingerprintef53131f3090b9ef
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in andialbrecht/sqlparse
- 2026-07-25Fix get_real_name for names with more than two dotted parts (#332)
- 2026-07-22Fix function grouping skipped for lowercase 'as' in CREATE TABLE AS SELECT
- 2025-11-29StatementSplitter
- 2025-11-28StatementSplitter
- 2024-07-15StatementSplitter
- 2024-04-13Raise SQLParseError instead of RecursionError.