I noticed that some stream_partitions call dot (.)...
# replication-troubleshooting
l
I noticed that some stream_partitions call dot (.) and bracket ([]). Which one would be used in what context?
k
Short answer: they’re interchangeable in Airbyte’s Jinja-based string interpolation. Use whichever fits your context or preference. Details: - Dot notation and bracket notation (with single quotes) resolve to the same value, e.g., "{{ parameters.name }}" == "{{ parameters['name'] }}". [[String interpolation 1.7](https://docs.airbyte.com/platform/1.7/connector-development/config-based/advanced-topics/string-interpolation); [String interpolation (current)](https://docs.airbyte.com/platform/connector-development/config-based/advanced-topics/string-interpolation)] Practical tip: - Use dot notation for simple keys without special characters: {{ stream_partition.order }} - Use bracket notation when keys contain characters not valid in dot notation (spaces, dashes, etc.): {{ stream_partition['order-id'] }} The docs do not mention any behavioral differences specific to stream_partition beyond general interpolation; both notations are equivalent. [[String interpolation 1.7](https://docs.airbyte.com/platform/1.7/connector-development/config-based/advanced-topics/string-interpolation)]
j
@Lillian Jiang I'd add some nuance to the AI answer/Airbyte docs on this. While these two can be equivalent in many/most cases, they aren't actually the same. As noted in the Jinja Variables docs (check the
Implementation
note in that section), the dot notation and subscript access (
[]
) check the same things, but in a different order: • Dot Notation: checks for an attribute first (
getattr
), then an item (
__getitem__
) • Subscript Access: checks for an item first (
__getitem__
), then an attribute (
getattr
) So whenever a variable has both an item and an attribute with the same name, these two syntaxes will return different results. . . . which can be very confusing. There's no good fix, other than to know this is possible. And in cases where you're producing the objects or know their attribute and item names, you also know how to predict which will win for a given syntax. But when this is coming from a component or such, you may be surprised when it doesn't work and need to try the other method. 🙃
l
Ah thank you! Is there a way to check the
getattr
and
__getitem__
of an object so we know which one to call beforehand?
j
No, Jinja doesn't expose these directly. But indirectly if you're ever not sure why something isn't working as expected, you can just switch to or compare dot notation vs. subscript since that would show you if they're returning something different. In the vast majority of cases these will be equivalent, but I've found when working with some components that isn't true (especially with common names like
name
where sometimes there's already some attribute that might be different than the item). Generally I agree with the docs though—use
.
when you can, unless you know there's an
attribute
of the same name when you actually want the
item
l
Thanks!
👍 1